Created
January 11, 2016 12:19
-
-
Save jeonghwan-kim/d3344a5a0a75f8822b44 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) { | |
// 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