Cli: Rails like migration generation

Created on 10 Jun 2014  路  11Comments  路  Source: sequelize/cli

The CLI should support rails like migration generation 谩 la:

sequelize migration:create --name=create-products

Which generates a new migration with a corresponding scaffold:

module.exports = {
  up: function(migration, DataTypes, done) {
    migration.createTable(
      'products',
      {
        // @todo implement
      }
    );
    done();
  },

  down: function(migration, DataTypes, done) {
    migration.dropTable('products');
    done();
  }
}
feature

Most helpful comment

+1

All 11 comments

Oringinal sequelize bin has this feature. :wink:

Original one just had the up/down skeleton i believe. It didn't have skeletons for createTable and similar

What @mickhansen said. Yes there is the feature of generating a skeleton. Yes you can specify the name of the migration. No you cannot generate a sensible skeleton, yet.

This issue is partially covered by #12

Having RoR/Django South like generated migrations would definitely take Sequelize to a whole new level.

+1 super keen for this

+1

While generating an initial migration along with a model using model:create is nice, the creation syntax doesn't support associations, which then have to be manually added in both the model _and_ in a migration (and boy, figuring out how to create FK relationships in a migration wasn't fun).

I would really rather model:create _only_ created simple models which I could then edit to add associations to, and migration:create could then take the edited model (with the associations) as an argument to generate the correct initial migration file, FKs and all: ./node_modules/.bin/sequelize migration:create --model server/models/person.js

This would still fall short of autogenerated migrations for model _changes_ (such as South and Alembic can do), but it would be a huge step up for starting a project.

+1

+1

Was this page helpful?
0 / 5 - 0 ratings