From 02ed71e3e0c239e1a7ccf190569b2d726a1722af Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Wed, 7 Jan 2026 20:27:02 -0500 Subject: [PATCH] Allow NULL workflow_id in executions table for quick commands Changes: - Modified executions table schema to allow NULL workflow_id - Removed foreign key constraint that prevented NULL values - Added migration to update existing table structure - Quick commands can now be stored without a workflow reference Co-Authored-By: Claude Sonnet 4.5 --- server.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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);