From b13f98416b58dd540967dcaf54c00af627642e77 Mon Sep 17 00:00:00 2001 From: jedarden Date: Tue, 28 Apr 2026 23:36:02 -0400 Subject: [PATCH] fix(api): add missing replay_feedback FK migration The replay_feedback table was missing its foreign key constraint to matches(match_id). This happened because CREATE TABLE IF NOT EXISTS doesn't add FKs to existing tables. Added an idempotent migration that checks for the constraint's existence before adding it, ensuring it's safe to run on both fresh installs and existing databases. Co-Authored-By: Claude Opus 4.7 --- cmd/acb-api/db.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/acb-api/db.go b/cmd/acb-api/db.go index 15439dc..736f6e2 100644 --- a/cmd/acb-api/db.go +++ b/cmd/acb-api/db.go @@ -61,6 +61,13 @@ DO $$ BEGIN END IF; END $$; +-- Add missing foreign key constraints (CREATE TABLE IF NOT EXISTS doesn't add FKs to existing tables) +DO $$ BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'replay_feedback_match_id_fkey') THEN + ALTER TABLE replay_feedback ADD CONSTRAINT replay_feedback_match_id_fkey FOREIGN KEY (match_id) REFERENCES matches(match_id); + END IF; +END $$; + CREATE TABLE IF NOT EXISTS series_games ( id BIGSERIAL PRIMARY KEY, series_id BIGINT NOT NULL REFERENCES series(id),