Skip to content

fix(migrations): Make org contributors provider+hostname migration safe for self-hosted instances - #120637

Merged
srest2021 merged 3 commits into
masterfrom
srest2021/1135-migration-fix
Jul 27, 2026
Merged

fix(migrations): Make org contributors provider+hostname migration safe for self-hosted instances#120637
srest2021 merged 3 commits into
masterfrom
srest2021/1135-migration-fix

Conversation

@srest2021

@srest2021 srest2021 commented Jul 27, 2026

Copy link
Copy Markdown
Member

Migration 1135 makes OrganizationContributors.provider/hostname NOT NULL, but it assumed the (getsentry-only) backfill had run first — so self-hosted instances with null rows fail VALIDATE, and because our migrations are non-atomic, leave behind an orphaned NOT VALID constraint that breaks every retry (see getsentry/self-hosted#4426, getsentry/self-hosted#4428).

This PR edits 1135 in place to first drop any orphaned constraints and delete the un-backfillable null rows (they carry no Seer billing implications for self-hosted), so the NOT NULL change then passes everywhere. SaaS already recorded 1135 as applied. The migration should now pass on new self-hosted releases.

We avoid trying to actually backfill the hostname and provider here, since to do so we'd have to access control silo integration data (which is why the backfill was written as a getsentry job).

See https://sentry.slack.com/archives/C0BGY3T8N8Y/p1785022037555599 for context

Comment thread src/sentry/migrations/1135_organizationcontributors_provider_hostname_not_null.py Outdated
@srest2021
srest2021 marked this pull request as ready for review July 27, 2026 16:42
@srest2021
srest2021 requested a review from a team as a code owner July 27, 2026 16:42
@srest2021
srest2021 requested a review from a team July 27, 2026 16:42
Comment thread src/sentry/migrations/1135_organizationcontributors_provider_hostname_not_null.py Outdated
Comment on lines +47 to +53
SafeRunSQL(
[
'ALTER TABLE "sentry_organizationcontributors" '
'DROP CONSTRAINT IF EXISTS "sentry_organizationcontributors_hostname_6f7999b1_notnull"',
'ALTER TABLE "sentry_organizationcontributors" '
'DROP CONSTRAINT IF EXISTS "sentry_organizationcontributors_provider_4cfc5f3a_notnull"',
],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume we have to do this since we have invalid constraints existing already that haven't been validated?

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.

Yep

@srest2021
srest2021 merged commit 845dd59 into master Jul 27, 2026
86 of 87 checks passed
@srest2021
srest2021 deleted the srest2021/1135-migration-fix branch July 27, 2026 20:08
srest2021 added a commit that referenced this pull request Jul 27, 2026
…n safe for self-hosted (#120689)

Relates to CW-1539, INC-2306.

Migration `1140` adds the `(organization_id, provider, hostname,
external_identifier)` uniqueness constraint, but it assumed the
(getsentry-only) dedup job had collapsed duplicates first — so
self-hosted instances with duplicate contributors fail the
`AddConstraint` and the upgrade breaks.

This is the same self-hosted gap as the hostname NOT NULL migration
(getsentry/self-hosted#4426, getsentry/self-hosted#4428, fixed in
#120637), just at the uniqueness
step.

This PR adds a dedup pass in place before the `AddConstraint`: iterate
the table and keep the lowest-id row per group, deleting the rest. Safe
on self-hosted, which has no Seer billing--similarly, we do not repoint
OrganizationContributorAction nor sum num_actions since they should all
be 0. SaaS already recorded `1140` as applied.
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