How to auto generate migrations with Sequelize CLI from Sequelize models?

前端 未结 10 1219
终归单人心
终归单人心 2020-11-29 16:52

I have a set of Sequelize models. I want to use migrations, not DB Sync.

Sequelize CLI seems to be able to do this, according to this article: \"When you use the CLI

10条回答
  •  北海茫月
    2020-11-29 17:37

    I created a small working "migration file generator". It creates files which are working perfectly fine using sequelize db:migrate - even with foreign keys!

    You can find it here: https://gist.github.com/manuelbieh/ae3b028286db10770c81

    I tested it in an application with 12 different models covering:

    • STRING, TEXT, ENUM, INTEGER, BOOLEAN, FLOAT as DataTypes

    • Foreign key constraints (even reciprocal (user belongsTo team, team belongsTo user as owner))

    • Indexes with name, method and unique properties

提交回复
热议问题