Repository navigation
feat(service-accounts): Only enforce unique names among active accounts - #129914
Merged
Merged
Conversation
Replace the (organization_id, name) unique constraint with a partial one on is_active=True. Deleted service accounts will be soft-deleted with is_active=False, and their names need to stay reusable. The new constraint is looser than the old one, so it ships before the soft-delete code change. Co-Authored-By: Shaun Kaasten <[email protected]>
Contributor
|
This PR has a migration; here is the generated SQL for for --
-- Create constraint service_accounts_serviceaccount_org_name_unique_active on model serviceaccount
--
CREATE UNIQUE INDEX CONCURRENTLY "service_accounts_serviceaccount_org_name_unique_active" ON "service_accounts_serviceaccount" ("organization_id", "name") WHERE "is_active";
--
-- Remove constraint service_accounts_serviceaccount_org_name_unique from model serviceaccount
--
ALTER TABLE "service_accounts_serviceaccount" DROP CONSTRAINT "service_accounts_serviceaccount_org_name_unique"; |
DominikB2014
approved these changes
Nov 4, 2026
gricha
approved these changes
Nov 4, 2026
markstory
approved these changes
Nov 4, 2026
markstory
left a comment
Member
There was a problem hiding this comment.
Looks good. The table is empty so constraints will build quickly.
skaasten
added a commit
that referenced
this pull request
Nov 5, 2026
PR 2 of the service account soft-delete plan. PR 1 (#129914) made names unique only among active accounts, so a deleted account's name can be reused. Deleting a service account now keeps the row and sets `is_active=False`, like `User`, instead of hard-deleting it. That keeps references such as `created_by_service_account_id` on dashboards pointing at a real account, and it makes the token work later in the plan simpler. The cell replica stays too, with `is_active=False`. `ServiceAccount.deactivate()` does the delete. It locks the active row, removes its project links, clears `all_projects` and turns the account off. Everything that reads an account through the API or RPC now treats a deleted account as missing (404 / `None`). The cell-side readers already reject inactive accounts. Deleted is now the only way to be inactive, so `isActive` is gone from the request and the response. In a response it was always `true`, and in a request only `true` was useful. Like other unknown fields, `isActive` in a request is now ignored. Seer's generated client still lists the field, but no Seer code reads or sends it, so it can drop out the next time the client is regenerated. Audit entries no longer record `is_active`. If two DELETE requests race, the second one gets a 404 and writes no audit entry. Left as is: - Seer's "Service account is inactive" error message. Seer tests match on it, and the plan marks the change as optional. - No new org-deletion test. Rows still go with the org through the existing cascade, and a test would only exercise that. <!-- junior-request-attribution:start --> via **shaun.kaasten**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CA89MBDQB%3A1793816514.925669 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CA89MBDQB%3A1793816514.925669) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CA89MBDQB%3A1793816514.925669/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Shaun Kaasten <[email protected]> Co-authored-by: Shaun Kaasten <[email protected]>
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.
First PR of the service accounts soft-delete plan. Deleting a service account will soon keep the row and set
is_active=False, the same way deleting a user works. Seer provisions accounts by name, so a deleted account's name has to stay reusable.This replaces the
(organization_id, name)unique constraint with a partial one onis_active = true. The new constraint is looser than the old one, so it's safe to deploy before the soft-delete code change. TheIntegrityErrorhandling for duplicate names in the endpoint and RPC doesn't change.The migration adds the new index before it drops the old constraint. Sentry's migration runner turns
AddConstraintintoCREATE UNIQUE INDEX CONCURRENTLY, which runs outside the transaction, so this order means names are never left unconstrained. The table is tiny, because there are no service accounts in production yet.Until the soft-delete PR lands, an account disabled with
isActive: falsealso frees its name. Turning it back on while a live account holds the same name returns the existing duplicate-name 400 from PUT.via shaun.kaasten.
--
View Session [Sentry]