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 <noreply@anthropic.com>
This commit is contained in:
2026-01-07 20:27:02 -05:00
parent b3806545bd
commit a8be111e04

View File

@@ -75,19 +75,33 @@ async function initDatabase() {
await connection.query(` await connection.query(`
CREATE TABLE IF NOT EXISTS executions ( CREATE TABLE IF NOT EXISTS executions (
id VARCHAR(36) PRIMARY KEY, id VARCHAR(36) PRIMARY KEY,
workflow_id VARCHAR(36) NOT NULL, workflow_id VARCHAR(36) NULL,
status VARCHAR(50) NOT NULL, status VARCHAR(50) NOT NULL,
started_by VARCHAR(255), started_by VARCHAR(255),
started_at TIMESTAMP NULL, started_at TIMESTAMP NULL,
completed_at TIMESTAMP NULL, completed_at TIMESTAMP NULL,
logs JSON, logs JSON,
FOREIGN KEY (workflow_id) REFERENCES workflows(id) ON DELETE CASCADE,
INDEX idx_workflow (workflow_id), INDEX idx_workflow (workflow_id),
INDEX idx_status (status), INDEX idx_status (status),
INDEX idx_started (started_at) 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'); console.log('Database tables initialized successfully');
} catch (error) { } catch (error) {
console.error('Database initialization error:', error); console.error('Database initialization error:', error);