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

- 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:
Torsten Schulz (local)
2026-04-17 12:01:25 +02:00
parent de9f2c853d
commit 70c381114b

View File

@@ -2,42 +2,44 @@
module.exports = { module.exports = {
up: async (queryInterface, Sequelize) => { up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn({ const table = { tableName: 'contact_message', schema: 'service' };
tableName: 'contact_message', const columns = await queryInterface.describeTable(table);
schema: 'service'
}, 'answer', { if (!columns.answer) {
type: Sequelize.TEXT, await queryInterface.addColumn(table, 'answer', {
allowNull: true type: Sequelize.TEXT,
}); allowNull: true
await queryInterface.addColumn({ });
tableName: 'contact_message', }
schema: 'service'
}, 'answered_at', { if (!columns.answered_at) {
type: Sequelize.DATE, await queryInterface.addColumn(table, 'answered_at', {
allowNull: true type: Sequelize.DATE,
}); allowNull: true
await queryInterface.addColumn({ });
tableName: 'contact_message', }
schema: 'service'
}, 'is_answered', { if (!columns.is_answered) {
type: Sequelize.BOOLEAN, await queryInterface.addColumn(table, 'is_answered', {
allowNull: false, type: Sequelize.BOOLEAN,
defaultValue: false allowNull: false,
}); defaultValue: false
});
}
}, },
down: async (queryInterface, Sequelize) => { down: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn({ const table = { tableName: 'contact_message', schema: 'service' };
tableName: 'contact_message', const columns = await queryInterface.describeTable(table);
schema: 'service'
}, 'answer'); if (columns.answer) {
await queryInterface.removeColumn({ await queryInterface.removeColumn(table, 'answer');
tableName: 'contact_message', }
schema: 'service' if (columns.answered_at) {
}, 'answered_at'); await queryInterface.removeColumn(table, 'answered_at');
await queryInterface.removeColumn({ }
tableName: 'contact_message', if (columns.is_answered) {
schema: 'service' await queryInterface.removeColumn(table, 'is_answered');
}, 'is_answered'); }
} }
}; };