Simple utility to automatically generate and manage sequelize migrations
npm i --save-dev sequelize-automatic-migrations
npm i -g sequelize-automatic-migrations
sequelize-automatic-migrations -c [/path/to/config] -e [environment name] -d [/path/to/models] -i [/path/to/migrations] -m [model-name]
Options:
-c, --config JSON file for Sequelize's constructor "options" flag object as defined here: https://sequelize.readthedocs.org/en/latest/api/sequelize/
-e, --node-env Node environment namemodels-directory
-d, --models-directory Path to models directory
-i, --migrations-directory Path to migrations directory
-m, --model-name Model name
node_modules/.bin/sequelize-automatic-migrations -c [/path/to/config] -e [environment name] -d [/path/to/models] -i [/path/to/migrations] -m [model-name]
sequelize-automatic-migrations -c ./config/database.json -e development -i ./db/migrate -d ./models -m User
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('User', {
id: {
type: Sequelize.INTEGER,
autoIncrement : true,
allowNull : false,
primaryKey : true,
},
login: {
type: Sequelize.STRING,
allowNull : false,
},
password: {
type: Sequelize.STRING,
allowNull : false,
},
firstName: {
type: Sequelize.STRING,
},
lastName: {
type: Sequelize.STRING,
},
isActivated: {
type: Sequelize.BOOLEAN,
},
createdAt: {
type: Sequelize.DATE,
allowNull : false,
},
})
.then( function() {
return queryInterface.addIndex(
'User',
["login"],
{
indexName: 'users_login_unique',
indicesType: 'UNIQUE'
}
)
});
},
down: function (queryInterface, Sequelize) {
return queryInterface.dropTable('User');
}
};