Created
January 11, 2016 12:33
-
-
Save jeonghwan-kim/5c6eccad7500c48a17ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
up: function (queryInterface, Sequelize) { | |
return [ | |
queryInterface.addColumn('User', 'name', { | |
type: Sequelize.STRING | |
}), | |
queryInterface.addColumn('User', 'nickname', { | |
type: Sequelize.STRING, | |
}) | |
]; | |
}, | |
down: function (queryInterface, Sequelize) { | |
return [ | |
queryInterface.removeColumn('Challenges', 'name'), | |
queryInterface.removeColumn('Challenges', 'nickname') | |
]; | |
} | |
}; |
"use strict";
module.exports = {
up: async (queryInterface, Sequelize) => {
let transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.addColumn(
"TicketActions",
"title",
{
type: Sequelize.STRING,
},
{ transaction },
);
await queryInterface.addColumn(
"TicketActions",
"uploadPath",
{
type: Sequelize.STRING,
},
{ transaction },
);
await queryInterface.addColumn(
"TicketActions",
"description",
{
type: Sequelize.STRING,
},
{ transaction },
);
await transaction.commit();
return Promise.resolve();
} catch (err) {
if (transaction) {
await transaction.rollback();
}
return Promise.reject(err);
}
},
down: async (queryInterface, Sequelize) => {
let transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.removeColumn("TicketActions", "title", { transaction });
await queryInterface.removeColumn("TicketActions", "uploadPath", { transaction });
await queryInterface.removeColumn("TicketActions", "description", { transaction });
await transaction.commit();
return Promise.resolve();
} catch (err) {
if (transaction) {
await transaction.rollback();
}
return Promise.reject(err);
}
},
};
Use transaction in case 1 query is failed.
Aren't all migrations run in transactions?
migrate function should return promise so add Promise.all
module.exports = {
up: function (queryInterface, Sequelize) {
return Promise.all([
queryInterface.addColumn('User', 'name', {
type: Sequelize.STRING
}),
queryInterface.addColumn('User', 'nickname', {
type: Sequelize.STRING,
})
]);
},
down: function (queryInterface, Sequelize) {
return Promise.all([
queryInterface.removeColumn('User', 'name'),
queryInterface.removeColumn('User', 'nickname')
]);
}
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you get
(or wrapper) didn't return a promise
error then you can try this gist