feat(migration): enhance contact_message migration to check for existing columns before adding/removing
Some checks failed
Deploy to production / deploy (push) Failing after 3m14s
Some checks failed
Deploy to production / deploy (push) Failing after 3m14s
- Updated the migration script for the contact_message table to conditionally add or remove columns based on their existence, improving migration safety and preventing errors during deployment. - This change ensures that the migration can be run multiple times without causing issues if the columns already exist or are missing. [force-deploy]
This commit is contained in:
@@ -2,42 +2,44 @@
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.addColumn({
|
||||
tableName: 'contact_message',
|
||||
schema: 'service'
|
||||
}, 'answer', {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true
|
||||
});
|
||||
await queryInterface.addColumn({
|
||||
tableName: 'contact_message',
|
||||
schema: 'service'
|
||||
}, 'answered_at', {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true
|
||||
});
|
||||
await queryInterface.addColumn({
|
||||
tableName: 'contact_message',
|
||||
schema: 'service'
|
||||
}, 'is_answered', {
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
});
|
||||
const table = { tableName: 'contact_message', schema: 'service' };
|
||||
const columns = await queryInterface.describeTable(table);
|
||||
|
||||
if (!columns.answer) {
|
||||
await queryInterface.addColumn(table, 'answer', {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true
|
||||
});
|
||||
}
|
||||
|
||||
if (!columns.answered_at) {
|
||||
await queryInterface.addColumn(table, 'answered_at', {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true
|
||||
});
|
||||
}
|
||||
|
||||
if (!columns.is_answered) {
|
||||
await queryInterface.addColumn(table, 'is_answered', {
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.removeColumn({
|
||||
tableName: 'contact_message',
|
||||
schema: 'service'
|
||||
}, 'answer');
|
||||
await queryInterface.removeColumn({
|
||||
tableName: 'contact_message',
|
||||
schema: 'service'
|
||||
}, 'answered_at');
|
||||
await queryInterface.removeColumn({
|
||||
tableName: 'contact_message',
|
||||
schema: 'service'
|
||||
}, 'is_answered');
|
||||
const table = { tableName: 'contact_message', schema: 'service' };
|
||||
const columns = await queryInterface.describeTable(table);
|
||||
|
||||
if (columns.answer) {
|
||||
await queryInterface.removeColumn(table, 'answer');
|
||||
}
|
||||
if (columns.answered_at) {
|
||||
await queryInterface.removeColumn(table, 'answered_at');
|
||||
}
|
||||
if (columns.is_answered) {
|
||||
await queryInterface.removeColumn(table, 'is_answered');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user