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 <noreply@anthropic.com>
This commit is contained in:
parent
ee8c7c37b2
commit
b13f98416b
1 changed files with 7 additions and 0 deletions
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue