Files
yourpart3/backend/migrations/20240913071145-add-answer-fields-to-contact_message.cjs
Torsten Schulz (local) 70c381114b
Some checks failed
Deploy to production / deploy (push) Failing after 3m14s
feat(migration): enhance contact_message migration to check for existing columns before adding/removing
- 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]
2026-04-17 12:01:25 +02:00

46 lines
1.2 KiB
JavaScript

'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
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) => {
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');
}
}
};