Loading
Draft: feat(oauth): store the Rails primary key as source_id
What
Add source_id BIGINT (nullable) to oauth_clients and oauth_refresh_tokens, on Postgres and YugabyteDB. It stores the gitlab-rails primary key of the replicated row: oauth_applications.id for clients, oauth_access_tokens.id for refresh tokens.
Why
The target state of Layer 4 reconciliation (gitlab-org/gitlab#632159) will compare Rails and IAM in ranges of (owning_cell_id, source_id). The Rails worker loops by id, so IAM must store the same key. Topology Service uses this pattern: it stores the Rails primary key in claims.source_id and ListRecords ranges by it. We agreed with @ifarkas to follow the same pattern as the Topology Service Cells worker.
How
source_idis required (> 0) onCreateClient,UpsertClientand the refresh tokenUpsert.ManagedClientreturns it.- Set once at insert on both tables. A later upsert never changes it, like
created_at. BIGINT, not Topology'sBYTES(16): both Rails primary keys arebigint.- NULL only for IAM-native (dynamic) clients. The registry accepts 0 only for a dynamic client, the same rule as
owning_cell_id.
Notes
- Breaking change: Rails
UpsertClientfails until Rails sendssource_id. Only the sandbox has data, and we fix it by hand. - Stacked on auth/iam!699. When it merges, this MR targets
main.
Related to gitlab-org/gitlab#628424
Edited by Daniele Bracciani