eggjs sequelize migrations

(Change models and migrations folder):

.sequelizerc is no use for me, so this article come.

What I did is

package.json


  "devDependencies": {
    "sequelize-cli": "^4.1.1",
  },

  "scripts": {
    "sequelize": "sequelize --options-path=database/options.js",
    "db:migrate:create": "sequelize --options-path=database/options.js migration:create --name",
    "db:migrate": "sequelize --options-path=database/options.js db:migrate",
    "db:migrate:rollback": "sequelize --options-path=database/options.js db:migrate:undo",

    "db:seed:create": "sequelize --options-path=database/options.js db:seed --name",
    "db:seed": "sequelize --options-path=database/options.js db:seed:all",
    "db:seed:rollback": "sequelize --options-path=database/options.js db:seed:undo:all",

  },


database/option.js

const path = require('path');
module.exports =  {

  config: path.join(__dirname, 'config.json'),
  'migrations-path': path.join(__dirname, 'migrations'),
  'seeders-path': path.join(__dirname, 'seeders'),
  'models-path': path.join(__dirname, 'model'),
}


npm run sequelize init:migrations 

then the migrations folder will created in database folder.

mind:

--options-path=database/options.js
this is important。

extend:

database/config.json

{
  "development": {
    "username": "***",
    "password": "***",
    "database": "***",
    "host": "***",
    "port": "3306",
    "dialect": "mysql",
    "migrationStorage": "json",
    "migrationStoragePath": "sequelizeMeta.json",
    "migrationStorageTableName": "sequelize_meta",
    "seederStorage": "json",
    "seederStoragePath": "sequelizeData.json",
    "seederStorageTableName": "sequelize_data"
  }
}

re.:

eggjs Sequelize https://eggjs.org/zh-cn/tutorials/sequelize.html

Change models and migrations folder https://github.com/sequelize/cli/issues/28

query-interface http://docs.sequelizejs.com/class/lib/query-interface.js~QueryInterface.html

egg-sequelize-demo https://github.com/yandongxu/egg-sequelize-demo

https://github.com/yandongxu/egg-sequelize-demo/blob/master/package.json

migrations http://docs.sequelizejs.com/manual/tutorial/migrations.html

你可能感兴趣的:(eggjs sequelize migrations)