4

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

  1. does sequelize have a way to initialize the first migrations file?
  2. is there a tool I can use when I modify models in sequelize, and generate the new migrations file automatically based off some diffing mechanism?

1 Answer 1

1

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

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.