4 ms·
What's everyone favorite library for doing Postgres migrations using node? I'm using knex.js and still doing migrations mostly by hand.
by rawrmaan 9y ago
What's everyone favorite library for doing Postgres migrations using node? I'm using knex.js and still doing migrations mostly by hand.
- ericcoleman 9y agoWhy not use knex migrations then? I've used it on several projects and it seems to work just fine
- peterjlee 9y agoI use Sequelize. I write migrations in Javascript using Promise chains. It does take some trial and error to figure out how to add join columns or create the join table so Sequelize knows how to work with it.
- Cymen 9y agoI use db-migrate but I have corresponding ...-{up,down}.sql files for each migration and write the migrations in SQL.
- girvo 9y agoI use TypeORM -- supports migrations, though not to the same power as whats discussed in the OP. https://typeorm.github.io https://typeorm.github.io
- cygned 9y agoWe have written our own migration workflow on top of pg-promise because all the alternatives didn't work out for us. We don't use an ORM because of several reasons and we favor SQL over SQL-abstractions. We use Bookshelf/knex in a quite large project and we had some trouble with the latter so that we decided to go with "raw" pg-promise. So what we basically have is a script that runs migration SQL files in order within a transaction and then uses COPY to seed the database from a folder of CSV files. Triggered by a shell script which itself can be run via yarn/npm.
- wseymour 9y agoI'm using knex too, and enjoy the workflow. The built-in primitives for creating and modifying tables work nicely. It gets a little messy when you need to go off-script and `CREATE TRIGGER`s, etc, but I think that knex's approach is still predictable and reliable.
- 0XAFFE 9y agoWe use umzug[1] a migrations framework which uses sequelize[2]. We use umzug/sequelize with TypeScript and its quite pleasant to work with. [1] https://github.com/sequelize/umzug https://github.com/sequelize/umzug [2] https://github.com/sequelize/sequelize https://github.com/sequelize/sequelize
- emidln 9y agoI use the same tool across whatever language I'm in. It requires a directory of `TIMESTAMP-LABEL.DIRECTION.sql` files and then sorts them to know the order. It compares that to a database table of completed migrations to know which to run. It is extremely stupid, and throws its hands up if an error occurs (so the user can step in to fix it). It doesn't wrap things in transactions for you (not all DDL is transactional in Postgres) so you have to manually add BEGIN; and COMMIT; if you want those things. It is glorious. I write a nice DSL called SQL for my database and there are never any surprises. If I want to write brittle migrations, idempotent migrations, transactional migrations, or data migrations, those are all on me. Anything more than this leads to needless debugging the tools and has never resulted in more clear or concise code.