From 02bc1129178bb1119bf3affabfd5b377f98d1319 Mon Sep 17 00:00:00 2001 From: Chris Veleris Date: Thu, 8 Jan 2026 00:42:20 +0200 Subject: [PATCH] Fix failing migration --- ...28000002-rename-project-state-to-status.js | 72 ++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/backend/migrations/20251228000002-rename-project-state-to-status.js b/backend/migrations/20251228000002-rename-project-state-to-status.js index cd6d2fd..0c68f0c 100644 --- a/backend/migrations/20251228000002-rename-project-state-to-status.js +++ b/backend/migrations/20251228000002-rename-project-state-to-status.js @@ -5,10 +5,78 @@ */ module.exports = { async up(queryInterface, Sequelize) { - await queryInterface.renameColumn('projects', 'state', 'status'); + const tableInfo = await queryInterface.describeTable('projects'); + + // Already renamed - skip + if ('status' in tableInfo && !('state' in tableInfo)) { + console.log( + 'Column already renamed from state to status, skipping' + ); + return; + } + + // Not yet renamed - do it + if ('state' in tableInfo && !('status' in tableInfo)) { + const dialect = queryInterface.sequelize.getDialect(); + if (dialect === 'sqlite') { + // Use raw SQL for SQLite (supported in SQLite 3.25+) + await queryInterface.sequelize.query( + 'ALTER TABLE projects RENAME COLUMN state TO status;' + ); + } else { + await queryInterface.renameColumn( + 'projects', + 'state', + 'status' + ); + } + console.log('Successfully renamed column state to status'); + return; + } + + // Edge case: both exist or neither exists + console.log( + 'Unexpected state: state=' + + ('state' in tableInfo) + + ', status=' + + ('status' in tableInfo) + ); }, async down(queryInterface, Sequelize) { - await queryInterface.renameColumn('projects', 'status', 'state'); + const tableInfo = await queryInterface.describeTable('projects'); + + // Already reverted - skip + if ('state' in tableInfo && !('status' in tableInfo)) { + console.log( + 'Column already renamed from status to state, skipping' + ); + return; + } + + // Not yet reverted - do it + if ('status' in tableInfo && !('state' in tableInfo)) { + const dialect = queryInterface.sequelize.getDialect(); + if (dialect === 'sqlite') { + await queryInterface.sequelize.query( + 'ALTER TABLE projects RENAME COLUMN status TO state;' + ); + } else { + await queryInterface.renameColumn( + 'projects', + 'status', + 'state' + ); + } + console.log('Successfully renamed column status to state'); + return; + } + + console.log( + 'Unexpected state: state=' + + ('state' in tableInfo) + + ', status=' + + ('status' in tableInfo) + ); }, };