chore(api): harmonize tenant_id width between registered_clients schema and API#174
Merged
dcadenas merged 2 commits intoApr 29, 2026
Conversation
Every other tenant_id column in this schema is BIGINT (tenants.id, users, refresh_tokens, oauth_authorizations, atproto_oauth_sessions, auth_events). 0008 was the lone INTEGER outlier and forced the i64 API surface to use ::BIGINT casts on every read. New migration is idempotent via a DO block guarded on information_schema.columns.data_type = integer, so re-runs are no-ops. Added a regression test that asserts the column type post-migration.
…IGINT With registered_clients.tenant_id widened to BIGINT, the four `tenant_id::BIGINT AS tenant_id` casts in list/get/create/update SELECT and RETURNING clauses are no-ops; remove them. Also drop the doc comment on RegisteredClient that explained the prior INTEGER/i64 mismatch — there is no longer a mismatch to document. Behavior unchanged: the 16 registered_clients_admin_test cases continue to pass (they exercise list/get/create/update/delete and assert tenant_id round- trips correctly).
NotThatKindOfDrLiz
approved these changes
Apr 29, 2026
Member
NotThatKindOfDrLiz
left a comment
There was a problem hiding this comment.
Reviewed. I agree with the shape of this PR. This is the right fix for the tenant_id width mismatch: a widening migration, removal of the compensating casts, and a regression test that locks the schema expectation in place.
I do not see a blocker here. The rollout and rollback story is straightforward, and the surrounding cloudbuild psql glob bug is useful context but not something this PR needs to solve.
Approving.
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.
Summary
The
registered_clients.tenant_idcolumn wasINTEGERwhile every othertenant_idcolumn in the schema isBIGINT. The Rust API surface usesi64everywhere, so PR #168 worked around the mismatch by castingtenant_id::BIGINT AS tenant_idon every read.This change widens the column to
BIGINTso the schema and the API surface agree. The casts go away and the impliciti64 → i32narrowing on writes goes away with them.Closes #171.
What Changed
The column type changes in a forward-only migration. The existing
0008_registered_clients.sqlhas already been applied in production, so editing it would break checksum tracking — the new migration is idempotent (guarded oninformation_schema.columns.data_type = 'integer') and safe to re-run.20260429000000_widen_registered_clients_tenant_id.sqlALTERs the column toBIGINTonly when its current type isinteger.core/src/repositories/registered_client.rsdrops the fourtenant_id::BIGINT AS tenant_idcasts (inlist,get,create RETURNING,update RETURNING) and the doc comment that explained the prior INTEGER/i64 mismatch.registered_clients_tenant_id_is_bigintqueriesinformation_schema.columnsand asserts the post-migration type.Testing
I ran the affected suites against a fresh local Postgres test database, plus clippy and fmt over the whole workspace.
cargo test -p keycast_api --test registered_clients_admin_test— 16 passed (CRUD round-trip, includingtenant_idequality on returned rows).cargo test -p keycast_api --test registered_clients_migration_test— 2 passed (existing seed test + new BIGINT type assertion).cargo test -p keycast_core— 50 passed.cargo clippy --all-targets --all-features— clean.cargo fmt --all -- --check— clean.I did not run the full e2e suite or test against a Cloud SQL instance — both rely on infra I cannot reach from this worktree.
Risks
The migration is a widening on an in-production table. PostgreSQL rewrites the column in place (small table, fast) and no values can be lost going
INTEGER → BIGINT.i64. Both deployment paths preserve this ordering: cloudbuild.yaml runs the migration step before the build/deploy steps, and the binary's--migrateruns migrations before serving.project_migration_pipeline_bug.md, the cloudbuild psql globdatabase/migrations/00[1-9][0-9]*.sqldoes NOT match2026*filenames, so prod actually applies recent migrations through the binary's--migrate(sqlx::migrate) path rather than the cloudbuild psql step. That bug is out of scope for chore(api): harmonize tenant_id width between registered_clients schema and API #171 — surfaced as a follow-up on chore(admin): add durable audit trail for registered_clients admin changes #170 already.