Skip to content

Instantly share code, notes, and snippets.

@jeonghwan-kim
Created January 11, 2016 12:19
Show Gist options
  • Save jeonghwan-kim/d3344a5a0a75f8822b44 to your computer and use it in GitHub Desktop.
Save jeonghwan-kim/d3344a5a0a75f8822b44 to your computer and use it in GitHub Desktop.
module.exports = {
up: function (queryInterface, Sequelize) {
// raw query
// add column and foreign key constrant
var sql = "ALTER TABLE `Friend`" +
" ADD COLUMN `UserId` BIGINT(20) UNSIGNED DEFAULT NULL" +
", ADD CONSTRAINT `fkUserIdInFriend` FOREIGN KEY (`UserId`) REFERENCES `User` (`id`) ON UPDATE CASCADE ON DELETE RESTRICT";
// run the query
return queryInterface.sequelize.query(sql, {
type: Sequelize.QueryTypes.RAW
});
},
down: function (queryInterface, Sequelize) {
var sql = "ALTER TABLE `Friend`" +
" DROP FOREIGN KEY `fkUserIdInFriend`, DROP COLUMN `UserId`";
return queryInterface.sequelize.query(sql, {
type: Sequelize.QueryTypes.RAW
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment