I want to add column via migrations after a certain column also index it (Normal mysql index not unique index). Is this possible via sequelize.js via migrations. If yes how and if no any alternatives for this via migrations.
Can we execute custom query in sequelize migrations.
Below is my existing migration file.
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('UserDetails', 'user_id', {
type: Sequelize.INTEGER,
});
},
down: function (queryInterface, Sequelize) {
return queryInterface.removeColumn('UserDetails', 'user_id');
}
};
You can pass after
or before
in the options to add column after some specified column.
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('UserDetails', 'user_id', {
type: Sequelize.INTEGER,
after: "some_column"
});
},
down: function (queryInterface, Sequelize) {
return queryInterface.removeColumn('UserDetails', 'user_id');
}
};
P.S.
after
option is only supported by MySQL
https://github.com/sequelize/sequelize/blob/master/lib/query-interface.js#L495
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With