Deleting a reminder that had already fired failed with FK violation 'reminder_runs_reminder_id_reminders_id_fk'. Add ON DELETE CASCADE so the run history is removed alongside its reminder. reminder_run_targets cascades on run_id (already), so the chain is: reminder → reminder_runs → reminder_run_targets, all removed in one go.
8 lines
371 B
SQL
8 lines
371 B
SQL
ALTER TABLE "reminder_runs" DROP CONSTRAINT "reminder_runs_reminder_id_reminders_id_fk";
|
|
--> statement-breakpoint
|
|
DO $$ BEGIN
|
|
ALTER TABLE "reminder_runs" ADD CONSTRAINT "reminder_runs_reminder_id_reminders_id_fk" FOREIGN KEY ("reminder_id") REFERENCES "public"."reminders"("id") ON DELETE cascade ON UPDATE no action;
|
|
EXCEPTION
|
|
WHEN duplicate_object THEN null;
|
|
END $$;
|