Created
June 25, 2019 08:31
-
-
Save repodevs/783f5e483ed035625a1536267f543aab to your computer and use it in GitHub Desktop.
Sequelize add or remove enum values
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, DataTypes) => { | |
return queryInterface.sequelize.query("ALTER TYPE enum_students_id_card_type ADD VALUE 'driving_license';"); | |
}, | |
down: (queryInterface, DataTypes) => { | |
// FIXME: Removing enum value is not supported by PostgreSQL, | |
// but there is any tricky way to do this. | |
// ref: https://stackoverflow.com/a/46244969, https://stackoverflow.com/a/25812436 | |
return queryInterface.sequelize.query("UPDATE students SET id_card_type = 'ktp' WHERE id_card_type = 'driving_license';") | |
.then(() => { | |
const query = `DELETE FROM pg_enum | |
WHERE enumlabel = 'driving_license' | |
AND enumtypid = (SELECT oid FROM pg_type WHERE typname = 'enum_students_id_card_type');`; | |
return queryInterface.sequelize.query(query); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment