IssueRaiser

Auto-Create Migrations

I know this has been discussed before, but it would be really helpful if sequelize could auto-create migration scripts based on differences in sequelizer and the database. I currently have a [fork I'm testing out](https://github.com/sequelize/cli/compare/master...jgr3go:auto-migrate?expand=1) that attempts to solve this issue, and I wanted to open up the discussion again to make sure this would be accepted by sequelize/the community. Right now the rules put into place for `sequelize migration:create:auto` does the following (note, this treats sequelize as _canon_, so it will attempt to resolve the migrations to create a state in the database that matches sequelizer imports): 1. Read model.js files from a new `config/models.json`, and import the model/column definitions into sequelizer. 2. Read all tables from the database and import the model/column definitions 3. Compare: - If a column exists in the database and not sequelizer, create `removeColumn()` migration - If a column exists in sequelizer and not database, create `addColumn()` migration - If a table exists in database and not in sequelizer, print a WARNING, unless `--drop` flag is present, in which case create a `dropTable()` migration - If a table exists in sequelizer and not database, do nothing. It's currently assumed sequelizer.sync() will take care of this. 4. Keep track of auto-migrations by filename convention: `{timestamp}-{model}-auto-{version}`, e.g. `20160129135511-users-auto-0002.js` . If

Posted by jgr3go on Jan 29, 2016, 8:10 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.5,000 issues0 comments

github (Software)

Auto-Create Migrations

jgr3goJan 29, 2016, 8:10 PM

I know this has been discussed before, but it would be really helpful if sequelize could auto-create migration scripts based on differences in sequelizer and the database. I currently have a [fork I'm testing out](https://github.com/sequelize/cli/compare/master...jgr3go:auto-migrate?expand=1) that attempts to solve this issue, and I wanted to open up the discussion again to make sure this would be accepted by sequelize/the community. Right now the rules put into place for `sequelize migration:create:auto` does the following (note, this treats sequelize as _canon_, so it will attempt to resolve the migrations to create a state in the database that matches sequelizer imports): 1. Read model.js files from a new `config/models.json`, and import the model/column definitions into sequelizer. 2. Read all tables from the database and import the model/column definitions 3. Compare: - If a column exists in the database and not sequelizer, create `removeColumn()` migration - If a column exists in sequelizer and not database, create `addColumn()` migration - If a table exists in database and not in sequelizer, print a WARNING, unless `--drop` flag is present, in which case create a `dropTable()` migration - If a table exists in sequelizer and not database, do nothing. It's currently assumed sequelizer.sync() will take care of this. 4. Keep track of auto-migrations by filename convention: `{timestamp}-{model}-auto-{version}`, e.g. `20160129135511-users-auto-0002.js` . If

Comments (0)

No comments yet. Start the discussion.

Comment on this issue