node-pg-migrate
node-pg-migrate copied to clipboard
Generate migrations from existing schema
When starting to use this module with an existing project and schema, it could be useful to generate the existing schema into migration files. This way you would have the entire DB structure expressed in your migration files.
For me in particular, when I run my test suite, I am generating the db structure from sequelize's "sync" method, meaning that my test db could end up having a slightly different schema than my real production schema. I would much rather just run the migrations on my test db to get it into the right structure, but that would require having the entire schema expressed within migrations.
This would likely require some other changes too though, being able to mark certain migrations (or even operations) as not relevant to a "load up my schema from blank state" type of migration run.
I have this in my backlog for a long time, but it is quite a big feature and I still can't find a time to do it :(
yeah its a big one for sure... maybe a simpler way to think about it is starting with a base .sql dump file and a helper command to create it?
pg_dump --clean --if-exists --no-owner --no-acl $DATABASE_URL > 0000000000000-init.sql :)
inspiration:
- https://github.com/graphile/postgraphile
- https://github.com/djrobstep/migra
my consideration is that everything I have is either in sql files or in the database. using this tool would require rewriting everything.
Would squashing existing migrations be the same as this?
No it is for cases you already have same schema in DB and you would like to start using migrations
@nurmuhammadsirat you could also occasionally clear out all your migrations are replace with a current snapshot of the database