Reputation: 4170
I don’t get how sequelize migrations workflow works. I have a greenfield project, the database is designed using SQL scripts. We used sequelize auto
to generate the models thereafter.
I need to now generate a migrations file starting out, so I can run the CLI to run SQL queries to create new tables with columns etc for locally provisioned databases.
There’s no 3rd party tools afaik to convert the SQL script I have into a Sequelize migrations file. I have to do this manually for 60 tables. There is a script method of auto-creating it, but it uses a seperate format that doesn’t have backward compatability for undoing migrations (sequelize-auto-migrations).
When I update the sequelize model schema in my file, there’s not a one off way command to have migrations file synchronize to those changes, via a diffing mechanisms based off the last migration execution ran.
This means I have to modify the model, AND modify the migrations file, leading to potential human error and duplicate redundant work.
so my issues are
Upvotes: 4
Views: 893
Reputation: 4170
okay I found out
For step 1, you can run a queryInterface.sequelize.query(<query>)
and take the SQL scripts / run them right in sequelize for initialization. https://sequelize.org/master/class/lib/query-interface.js~QueryInterface.html. This short code references the sql script as the first migration
For step 2, you can modify the file and update the migrations manually, and run sequelize-auto
to pull the latest changes from the remote/local db
Upvotes: 1