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:
18
server.js
18
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);
|
||||
|
||||
Reference in New Issue
Block a user