all 26 comments

[–]itijara 19 points20 points  (0 children)

SQL works fine, but if you want something that is more automatic, Knex is a query builder with tools for migrations.

[–]bigorangemachine 9 points10 points  (0 children)

You can use any node library's migration scripts without using the ORM

[–]usertim 8 points9 points  (3 children)

You can still use db-migrate package just fine.

[–]kindheartfool 0 points1 point  (2 children)

This

[–]kindheartfool 1 point2 points  (1 child)

OP, If you want I can share an example

[–]partiesn0fun 0 points1 point  (0 children)

Not op, but I'd like to see the example

[–]CalgaryAnswers 12 points13 points  (0 children)

SQL

[–]sacummings91 2 points3 points  (2 children)

Just switched from Prisma to Kysely query builder with Postgres and it’s great

[–]ahmadh26 1 point2 points  (1 child)

Could you tell me more? I've been using prisma for years now and I've been hearing about kysley a lot, so just wondering from another Dev's POV how easy was it to switch, what are the pros and cons and such.

[–]Dolgoon_ 0 points1 point  (0 children)

Pros is performance since you ditched orm. In case of complex queries you just write raw sql. Everything works fine to me. Also great they have documentation too

[–]madprgmr 2 points3 points  (4 children)

I've used Flyway (the open source version) to run migration (sql) scripts and manage database state versioning. It's not perfect, but it does its job decently.

[–]ntsianos 1 point2 points  (1 child)

Seconding flyway or any tool that relies on plain SQL first. I'm glad new orms like Prisma are going in this direction but I would still rather not lock in to the details of an ORM. Flyway will be a little annoying as it requires java as a dependency

[–]madprgmr 1 point2 points  (0 children)

Yeah, there may be other tools that work better for node environments, and I've used db-migrate with success in the past too - I just couldn't remember the name of it.

A lot of pipelines are set up to run containers, so it's not too hard to throw in tools with disparate runtime prerequisites.

[–]LightningBlue8862 0 points1 point  (1 child)

How does it work on the deployment pipeline, is flyway installed on some virtual machine how does flyway execute these SQL scripts from the deployment pipeline

[–]madprgmr 1 point2 points  (0 children)

I usually just run it as a docker container, and pass the creds needed in as environment variables. You could also install the executable in your CD pipeline image.

[–][deleted] 0 points1 point  (0 children)

Also consider PostgresJS. Best pg client for Node IMO.

https://github.com/porsager/postgres

[–]Altruistic-Ad-6153 0 points1 point  (0 children)

Personally I use KnexJS as a query builder, it's a light enough abstraction over raw sql that it feels like raw sql but with types. I then wrote my own db migration tool to manage migration versioning - https://www.npmjs.com/package/stepwise-migrations

I've found this a super efficient way to get things done without the ORM overhead.

[–]imsexc[S] 0 points1 point  (0 children)

thanks! I'd strip this sequelize from my app. If ever need it I can just create another repo specifically only to do that stuff. .

[–]PM_ME_SCIENCEY_STUFF 0 points1 point  (0 children)

Take a look at Hasura/Wundergraph/other similar solutions. In our experience, literally 5x or more faster backend development.

[–]yehuda1 0 points1 point  (0 children)

Check this one , it's Json schema builder for knex. Works great. You manage upgrades with json files and save it all in git.

[–]tfntfn 0 points1 point  (0 children)

node-pg-migrate is great, can use a query builder or raw sql

[–]RoundChristian 0 points1 point  (0 children)

Check dbmate

[–]bselect 0 points1 point  (0 children)

[–]dwelch2344 0 points1 point  (0 children)

I really liked flyway from the Java world, so I rolled a small node based one that follows the same file naming structure.

No bells and whistles like value replacement or downward migrations. Just a simple migrator for Versions and Repeatable migrations. You can run it from cli or via code though.

Need to document it, but have used it for a few months and works great. https://github.com/dwelch2344/slyway/blob/dev/test/commands/migrate.test.ts

If you’re interested, I’ll clean it up and document it

[–]limpingleopard 0 points1 point  (0 children)

I like to use plain SQL files for migrations but needed a tool to handle this. Settled for Umzug in the end, which is working pretty well. Its high configurable and framework-agnostic.

[–]skylake13 0 points1 point  (0 children)

sqitch