fix(migrations): Make org contributors provider+hostname migration safe for self-hosted instances - #120637
Merged
Merged
Conversation
srest2021
commented
Jul 27, 2026
wedamija
approved these changes
Jul 27, 2026
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"', | ||
| ], |
Member
There was a problem hiding this comment.
I assume we have to do this since we have invalid constraints existing already that haven't been validated?
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.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migration
1135makesOrganizationContributors.provider/hostnameNOT NULL, but it assumed the (getsentry-only) backfill had run first — so self-hosted instances with null rows failVALIDATE, and because our migrations are non-atomic, leave behind an orphanedNOT VALIDconstraint that breaks every retry (see getsentry/self-hosted#4426, getsentry/self-hosted#4428).This PR edits
1135in 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 recorded1135as 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