Skip to content

feat(releases): validate the foreign keys into sentry_release - #127327

Merged
ldelvoye merged 1 commit into
masterfrom
ldelvoye/feat/validate-release-foreign-keys
Oct 14, 2026
Merged

ldelvoye merged 1 commit into
masterfrom
ldelvoye/feat/validate-release-foreign-keys

Conversation

@ldelvoye

Copy link
Copy Markdown
Member

resolves INFRENG-726

Adds a post-deployment migration that validates the foreign keys into sentry_release, which the 1207 primary key swap re-added as NOT VALID.

@markstory this is the follow-up you asked for on #126200. Each table is validated in its own transaction with no statement timeout, and sentry_groupedmessage goes last. Validation only takes SHARE UPDATE EXCLUSIVE on the child table and ROW SHARE on sentry_release, so reads and writes keep flowing. A rerun after an interrupted run skips the keys that are already validated, so it's safe to cancel and restart.

@ldelvoye
ldelvoye requested a review from markstory October 13, 2026 22:36
@ldelvoye
ldelvoye requested a review from a team as a code owner October 13, 2026 22:37
@linear-code

linear-code Bot commented Oct 13, 2026

Copy link
Copy Markdown

INFRENG-726

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 13, 2026
@ldelvoye
ldelvoye requested a review from a team October 13, 2026 22:39
@github-actions

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/1210_release_validate_foreign_keys.py

for 1210_release_validate_foreign_keys in sentry

--
-- Raw SQL operation
--

DO $$
DECLARE
    fk_name text;
BEGIN
    FOR fk_name IN
        SELECT conname
        FROM pg_constraint
        WHERE contype = 'f'
          AND conrelid = 'sentry_deploy'::regclass
          AND confrelid = 'sentry_release'::regclass
          AND NOT convalidated
    LOOP
        EXECUTE format('ALTER TABLE %I VALIDATE CONSTRAINT %I', 'sentry_deploy', fk_name);
    END LOOP;
END $$;

--
-- Raw SQL operation
--

DO $$
DECLARE
    fk_name text;
BEGIN
    FOR fk_name IN
        SELECT conname
        FROM pg_constraint
        WHERE contype = 'f'
          AND conrelid = 'sentry_distribution'::regclass
          AND confrelid = 'sentry_release'::regclass
          AND NOT convalidated
    LOOP
        EXECUTE format('ALTER TABLE %I VALIDATE CONSTRAINT %I', 'sentry_distribution', fk_name);
    END LOOP;
END $$;

--
-- Raw SQL operation
--

DO $$
DECLARE
    fk_name text;
BEGIN
    FOR fk_name IN
        SELECT conname
        FROM pg_constraint
        WHERE contype = 'f'
          AND conrelid = 'sentry_groupresolution'::regclass
          AND confrelid = 'sentry_release'::regclass
          AND NOT convalidated
    LOOP
        EXECUTE format('ALTER TABLE %I VALIDATE CONSTRAINT %I', 'sentry_groupresolution', fk_name);
    END LOOP;
END $$;

--
-- Raw SQL operation
--

DO $$
DECLARE
    fk_name text;
BEGIN
    FOR fk_name IN
        SELECT conname
        FROM pg_constraint
        WHERE contype = 'f'
          AND conrelid = 'sentry_release_project'::regclass
          AND confrelid = 'sentry_release'::regclass
          AND NOT convalidated
    LOOP
        EXECUTE format('ALTER TABLE %I VALIDATE CONSTRAINT %I', 'sentry_release_project', fk_name);
    END LOOP;
END $$;

--
-- Raw SQL operation
--

DO $$
DECLARE
    fk_name text;
BEGIN
    FOR fk_name IN
        SELECT conname
        FROM pg_constraint
        WHERE contype = 'f'
          AND conrelid = 'sentry_releaseactivity'::regclass
          AND confrelid = 'sentry_release'::regclass
          AND NOT convalidated
    LOOP
        EXECUTE format('ALTER TABLE %I VALIDATE CONSTRAINT %I', 'sentry_releaseactivity', fk_name);
    END LOOP;
END $$;

--
-- Raw SQL operation
--

DO $$
DECLARE
    fk_name text;
BEGIN
    FOR fk_name IN
        SELECT conname
        FROM pg_constraint
        WHERE contype = 'f'
          AND conrelid = 'sentry_releasecommit'::regclass
          AND confrelid = 'sentry_release'::regclass
          AND NOT convalidated
    LOOP
        EXECUTE format('ALTER TABLE %I VALIDATE CONSTRAINT %I', 'sentry_releasecommit', fk_name);
    END LOOP;
END $$;

--
-- Raw SQL operation
--

DO $$
DECLARE
    fk_name text;
BEGIN
    FOR fk_name IN
        SELECT conname
        FROM pg_constraint
        WHERE contype = 'f'
          AND conrelid = 'sentry_releaseheadcommit'::regclass
          AND confrelid = 'sentry_release'::regclass
          AND NOT convalidated
    LOOP
        EXECUTE format('ALTER TABLE %I VALIDATE CONSTRAINT %I', 'sentry_releaseheadcommit', fk_name);
    END LOOP;
END $$;

--
-- Raw SQL operation
--

DO $$
DECLARE
    fk_name text;
BEGIN
    FOR fk_name IN
        SELECT conname
        FROM pg_constraint
        WHERE contype = 'f'
          AND conrelid = 'sentry_releaseprojectenvironment'::regclass
          AND confrelid = 'sentry_release'::regclass
          AND NOT convalidated
    LOOP
        EXECUTE format('ALTER TABLE %I VALIDATE CONSTRAINT %I', 'sentry_releaseprojectenvironment', fk_name);
    END LOOP;
END $$;

--
-- Raw SQL operation
--

DO $$
DECLARE
    fk_name text;
BEGIN
    FOR fk_name IN
        SELECT conname
        FROM pg_constraint
        WHERE contype = 'f'
          AND conrelid = 'sentry_groupedmessage'::regclass
          AND confrelid = 'sentry_release'::regclass
          AND NOT convalidated
    LOOP
        EXECUTE format('ALTER TABLE %I VALIDATE CONSTRAINT %I', 'sentry_groupedmessage', fk_name);
    END LOOP;
END $$;

@ldelvoye ldelvoye left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌱 Looked through this, no blocking issues.

CI had failures when I looked; this is a verdict on the code.

This review was generated by a bot; every message tagged 🌱 is from it. Reply with bot: to ask it something.

@ldelvoye
ldelvoye merged commit 22fb5d5 into master Oct 14, 2026
89 of 90 checks passed
@ldelvoye
ldelvoye deleted the ldelvoye/feat/validate-release-foreign-keys branch October 14, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants