diff --git a/server.js b/server.js index a416bf6..892f969 100644 --- a/server.js +++ b/server.js @@ -75,19 +75,33 @@ async function initDatabase() { await connection.query(` CREATE TABLE IF NOT EXISTS executions ( id VARCHAR(36) PRIMARY KEY, - workflow_id VARCHAR(36) NOT NULL, + workflow_id VARCHAR(36) NULL, status VARCHAR(50) NOT NULL, started_by VARCHAR(255), started_at TIMESTAMP NULL, completed_at TIMESTAMP NULL, logs JSON, - FOREIGN KEY (workflow_id) REFERENCES workflows(id) ON DELETE CASCADE, INDEX idx_workflow (workflow_id), INDEX idx_status (status), INDEX idx_started (started_at) ) `); + // Migrate existing executions table to allow NULL workflow_id + try { + await connection.query(` + ALTER TABLE executions + MODIFY workflow_id VARCHAR(36) NULL, + DROP FOREIGN KEY executions_ibfk_1 + `); + console.log('Executions table migrated to allow NULL workflow_id'); + } catch (error) { + // Ignore error if foreign key doesn't exist or already modified + if (!error.message.includes('check that column/key exists')) { + console.log('Migration note:', error.message); + } + } + console.log('Database tables initialized successfully'); } catch (error) { console.error('Database initialization error:', error);