Skip to content

Instantly share code, notes, and snippets.

@tolumide-ng
Created August 28, 2019 12:39
Show Gist options
  • Save tolumide-ng/943c3f63566aacc95f8e72bdbfe70bf2 to your computer and use it in GitHub Desktop.
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
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