Update migration to solve ON DELETE CASCADE
This commit is contained in:
@@ -1,40 +1,25 @@
|
|||||||
-- Update CHECK constraint to include cleanupscript
|
-- 1. Add the replacement column with the wider CHECK
|
||||||
PRAGMA foreign_keys = OFF;
|
ALTER TABLE execution_processes
|
||||||
|
ADD COLUMN process_type_new TEXT NOT NULL DEFAULT 'setupscript'
|
||||||
|
CHECK (process_type_new IN ('setupscript',
|
||||||
|
'cleanupscript', -- new value 🎉
|
||||||
|
'codingagent',
|
||||||
|
'devserver'));
|
||||||
|
|
||||||
-- Create new table with updated constraint
|
-- 2. Copy existing values across
|
||||||
CREATE TABLE execution_processes_new (
|
UPDATE execution_processes
|
||||||
id BLOB PRIMARY KEY,
|
SET process_type_new = process_type;
|
||||||
task_attempt_id BLOB NOT NULL,
|
|
||||||
process_type TEXT NOT NULL DEFAULT 'setupscript'
|
|
||||||
CHECK (process_type IN ('setupscript','cleanupscript','codingagent','devserver')),
|
|
||||||
status TEXT NOT NULL DEFAULT 'running'
|
|
||||||
CHECK (status IN ('running','completed','failed','killed')),
|
|
||||||
command TEXT NOT NULL,
|
|
||||||
args TEXT, -- JSON array of arguments
|
|
||||||
working_directory TEXT NOT NULL,
|
|
||||||
stdout TEXT,
|
|
||||||
stderr TEXT,
|
|
||||||
exit_code INTEGER,
|
|
||||||
started_at TEXT NOT NULL DEFAULT (datetime('now', 'subsec')),
|
|
||||||
completed_at TEXT,
|
|
||||||
created_at TEXT NOT NULL DEFAULT (datetime('now', 'subsec')),
|
|
||||||
updated_at TEXT NOT NULL DEFAULT (datetime('now', 'subsec')),
|
|
||||||
executor_type TEXT,
|
|
||||||
FOREIGN KEY (task_attempt_id) REFERENCES task_attempts(id) ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Copy data from old table
|
-- 3. Drop any indexes that mention the old column
|
||||||
INSERT INTO execution_processes_new SELECT * FROM execution_processes;
|
DROP INDEX IF EXISTS idx_execution_processes_type;
|
||||||
|
|
||||||
-- Drop old table
|
-- 4. Remove the old column (requires 3.35+)
|
||||||
DROP TABLE execution_processes;
|
ALTER TABLE execution_processes DROP COLUMN process_type;
|
||||||
|
|
||||||
-- Rename new table
|
-- 5. Rename the new column back to the canonical name
|
||||||
ALTER TABLE execution_processes_new RENAME TO execution_processes;
|
ALTER TABLE execution_processes
|
||||||
|
RENAME COLUMN process_type_new TO process_type;
|
||||||
|
|
||||||
-- Recreate indexes
|
-- 6. Re-create the index
|
||||||
CREATE INDEX idx_execution_processes_task_attempt_id ON execution_processes(task_attempt_id);
|
CREATE INDEX idx_execution_processes_type
|
||||||
CREATE INDEX idx_execution_processes_status ON execution_processes(status);
|
ON execution_processes(process_type);
|
||||||
CREATE INDEX idx_execution_processes_type ON execution_processes(process_type);
|
|
||||||
|
|
||||||
PRAGMA foreign_keys = ON;
|
|
||||||
Reference in New Issue
Block a user