diff options
| author | soryu <soryu@soryu.co> | 2026-01-11 05:52:14 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-01-15 00:21:16 +0000 |
| commit | 87044a747b47bd83249d61a45842c7f7b2eae56d (patch) | |
| tree | ef2000ce79ffcc2723ef841acef5aa1deb1d5378 /makima/migrations/20250112000000_cascade_delete_contract_children.sql | |
| parent | 077820c4167c168072d217a1b01df840463a12a8 (diff) | |
| download | soryu-87044a747b47bd83249d61a45842c7f7b2eae56d.tar.gz soryu-87044a747b47bd83249d61a45842c7f7b2eae56d.zip | |
Contract system
Diffstat (limited to 'makima/migrations/20250112000000_cascade_delete_contract_children.sql')
| -rw-r--r-- | makima/migrations/20250112000000_cascade_delete_contract_children.sql | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/makima/migrations/20250112000000_cascade_delete_contract_children.sql b/makima/migrations/20250112000000_cascade_delete_contract_children.sql new file mode 100644 index 0000000..6ef8a43 --- /dev/null +++ b/makima/migrations/20250112000000_cascade_delete_contract_children.sql @@ -0,0 +1,15 @@ +-- Change files and tasks to cascade delete when contract is deleted +-- Previously these were ON DELETE SET NULL, which orphaned records + +-- Drop existing foreign key constraints +ALTER TABLE files DROP CONSTRAINT IF EXISTS files_contract_id_fkey; +ALTER TABLE tasks DROP CONSTRAINT IF EXISTS tasks_contract_id_fkey; + +-- Re-add with CASCADE +ALTER TABLE files + ADD CONSTRAINT files_contract_id_fkey + FOREIGN KEY (contract_id) REFERENCES contracts(id) ON DELETE CASCADE; + +ALTER TABLE tasks + ADD CONSTRAINT tasks_contract_id_fkey + FOREIGN KEY (contract_id) REFERENCES contracts(id) ON DELETE CASCADE; |
