Skip to content

chore(api): harmonize tenant_id width between registered_clients schema and API#174

Merged
dcadenas merged 2 commits into
mainfrom
feat/171-follow-up-harmonize-tenant-id-width-between-registe
Apr 29, 2026
Merged

chore(api): harmonize tenant_id width between registered_clients schema and API#174
dcadenas merged 2 commits into
mainfrom
feat/171-follow-up-harmonize-tenant-id-width-between-registe

Conversation

@dcadenas
Copy link
Copy Markdown
Contributor

Summary

The registered_clients.tenant_id column was INTEGER while every other tenant_id column in the schema is BIGINT. The Rust API surface uses i64 everywhere, so PR #168 worked around the mismatch by casting tenant_id::BIGINT AS tenant_id on every read.

This change widens the column to BIGINT so the schema and the API surface agree. The casts go away and the implicit i64 → i32 narrowing on writes goes away with them.

Closes #171.

What Changed

The column type changes in a forward-only migration. The existing 0008_registered_clients.sql has already been applied in production, so editing it would break checksum tracking — the new migration is idempotent (guarded on information_schema.columns.data_type = 'integer') and safe to re-run.

  • New migration 20260429000000_widen_registered_clients_tenant_id.sql ALTERs the column to BIGINT only when its current type is integer.
  • core/src/repositories/registered_client.rs drops the four tenant_id::BIGINT AS tenant_id casts (in list, get, create RETURNING, update RETURNING) and the doc comment that explained the prior INTEGER/i64 mismatch.
  • New regression test registered_clients_tenant_id_is_bigint queries information_schema.columns and 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, including tenant_id equality 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.
  • Red-green: confirmed the new migration test fails on the pre-migration schema and passes after the migration runs.

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.

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).
Copy link
Copy Markdown
Member

@NotThatKindOfDrLiz NotThatKindOfDrLiz left a comment

Choose a reason for hiding this comment

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

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.

@dcadenas dcadenas marked this pull request as ready for review April 29, 2026 13:07
@NotThatKindOfDrLiz NotThatKindOfDrLiz changed the title chore: Follow-up: harmonize tenant_id width between registered_clients schema and API chore(api): harmonize tenant_id width between registered_clients schema and API Apr 29, 2026
@dcadenas dcadenas merged commit b74aaba into main Apr 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(api): harmonize tenant_id width between registered_clients schema and API

2 participants