Created
August 28, 2019 12:39
-
-
Save tolumide-ng/943c3f63566aacc95f8e72bdbfe70bf2 to your computer and use it in GitHub Desktop.
How to Drop an enum column and replace with a new datatype in sequelize ORM
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: (queryInterface, Sequelize) => { | |
return Promise.all([ | |
(queryInterface.removeColumn('Ratings', 'ratings'), | |
queryInterface.sequelize.query('DROP TYPE "enum_Ratings_ratings";'), | |
queryInterface.addColumn('Ratings', 'ratings', { | |
type: Sequelize.INTEGER, | |
validate: { | |
isInt: true, | |
isIn: [[1, 2, 3, 4, 5]], | |
min: 0 | |
} | |
})) | |
]); | |
}, | |
down: (queryInterface, Sequelize) => { | |
return Promise.all([ | |
queryInterface.removeColumn('Ratings', 'ratings'), | |
queryInterface.addColumn('Ratings', 'ratings', { | |
type: Sequelize.ENUM, | |
values: [1, 2, 3, 4, 5], | |
allowNull: false | |
}) | |
]); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment