diff --git a/backend/migrations/20250720000000_add_cleanupscript_to_process_type_constraint.sql b/backend/migrations/20250720000000_add_cleanupscript_to_process_type_constraint.sql index 0c332cbd..fc875be4 100644 --- a/backend/migrations/20250720000000_add_cleanupscript_to_process_type_constraint.sql +++ b/backend/migrations/20250720000000_add_cleanupscript_to_process_type_constraint.sql @@ -1,40 +1,25 @@ --- Update CHECK constraint to include cleanupscript -PRAGMA foreign_keys = OFF; +-- 1. Add the replacement column with the wider CHECK +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 -CREATE TABLE execution_processes_new ( - id BLOB PRIMARY KEY, - 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 -); +-- 2. Copy existing values across +UPDATE execution_processes + SET process_type_new = process_type; --- Copy data from old table -INSERT INTO execution_processes_new SELECT * FROM execution_processes; +-- 3. Drop any indexes that mention the old column +DROP INDEX IF EXISTS idx_execution_processes_type; --- Drop old table -DROP TABLE execution_processes; +-- 4. Remove the old column (requires 3.35+) +ALTER TABLE execution_processes DROP COLUMN process_type; --- Rename new table -ALTER TABLE execution_processes_new RENAME TO execution_processes; +-- 5. Rename the new column back to the canonical name +ALTER TABLE execution_processes + RENAME COLUMN process_type_new TO process_type; --- Recreate indexes -CREATE INDEX idx_execution_processes_task_attempt_id ON execution_processes(task_attempt_id); -CREATE INDEX idx_execution_processes_status ON execution_processes(status); -CREATE INDEX idx_execution_processes_type ON execution_processes(process_type); - -PRAGMA foreign_keys = ON; +-- 6. Re-create the index +CREATE INDEX idx_execution_processes_type + ON execution_processes(process_type); \ No newline at end of file