cli icon indicating copy to clipboard operation
cli copied to clipboard

Rails like migration generation

Open sdepold opened this issue 10 years ago • 11 comments

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();
  }
}

sdepold avatar Jun 10 '14 10:06 sdepold

Oringinal sequelize bin has this feature. :wink:

dgmike avatar Jun 11 '14 10:06 dgmike

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

mickhansen avatar Jun 11 '14 11:06 mickhansen

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.

sdepold avatar Jun 12 '14 18:06 sdepold

This issue is partially covered by #12

sdepold avatar Jun 28 '14 06:06 sdepold

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

ekmartin avatar Dec 28 '14 20:12 ekmartin

+1 super keen for this

super-cache-money avatar Oct 09 '15 10:10 super-cache-money

+1

mjhea0 avatar Dec 02 '15 17:12 mjhea0

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.

webmaven avatar Mar 04 '16 05:03 webmaven

+1

lsroman avatar Oct 15 '16 10:10 lsroman

+1

cellis avatar Jan 03 '17 04:01 cellis

Same here: https://github.com/sequelize/cli/issues/257

MateuszG avatar Feb 02 '17 20:02 MateuszG