diff --git a/internal/database/migrations/20260106090725_fk_recording_cascade.down.sql b/internal/database/migrations/20260106090725_fk_recording_cascade.down.sql new file mode 100644 index 00000000..efe3954a --- /dev/null +++ b/internal/database/migrations/20260106090725_fk_recording_cascade.down.sql @@ -0,0 +1,21 @@ +BEGIN; + +DO $$ +BEGIN + IF EXISTS ( + SELECT 1 + FROM pg_constraint + WHERE conname = 'fk_recordings_project_flock_kandang' + ) THEN + ALTER TABLE recordings + DROP CONSTRAINT fk_recordings_project_flock_kandang; + END IF; +END $$; + +ALTER TABLE recordings + ADD CONSTRAINT fk_recordings_project_flock_kandang + FOREIGN KEY (project_flock_kandangs_id) + REFERENCES project_flock_kandangs (id) + ON DELETE RESTRICT ON UPDATE CASCADE; + +COMMIT; diff --git a/internal/database/migrations/20260106090725_fk_recording_cascade.up.sql b/internal/database/migrations/20260106090725_fk_recording_cascade.up.sql new file mode 100644 index 00000000..2600827d --- /dev/null +++ b/internal/database/migrations/20260106090725_fk_recording_cascade.up.sql @@ -0,0 +1,21 @@ +BEGIN; + +DO $$ +BEGIN + IF EXISTS ( + SELECT 1 + FROM pg_constraint + WHERE conname = 'fk_recordings_project_flock_kandang' + ) THEN + ALTER TABLE recordings + DROP CONSTRAINT fk_recordings_project_flock_kandang; + END IF; +END $$; + +ALTER TABLE recordings + ADD CONSTRAINT fk_recordings_project_flock_kandang + FOREIGN KEY (project_flock_kandangs_id) + REFERENCES project_flock_kandangs (id) + ON DELETE CASCADE ON UPDATE CASCADE; + +COMMIT;