Skip to content

fix: drop unused oauth_tokens table from 003 (closes #97)#120

Merged
rsharath merged 1 commit intomainfrom
drop-unused-oauth-tokens-table
May 6, 2026
Merged

fix: drop unused oauth_tokens table from 003 (closes #97)#120
rsharath merged 1 commit intomainfrom
drop-unused-oauth-tokens-table

Conversation

@rsharath
Copy link
Copy Markdown
Contributor

@rsharath rsharath commented May 5, 2026

Summary

Closes #97. Removes the never-wired oauth_tokens table directly from migrations/003_oauth_clients.up.sql (and the matching DROP statements from the down file), instead of layering a separate drop migration on top.

Approach changed mid-PR (per @saucam's review)

The original commit added 015_drop_oauth_tokens.{up,down}.sql. Saucam asked: "can we just drop these directly without adding a new migration?" — and in this case, yes: ZeroID has not been deployed to any persistent environment yet, so every install runs migrations from scratch on the current SQL. Editing 003 in place produces the same end state everywhere.

If/when a real deployment exists, future cleanups of unused tables MUST use the layered-migration pattern. Migration files become append-only the moment any deployment runs them, because schema_migrations.version says "this version was applied" while the actual rows behave however the contemporaneous SQL dictated. Two deployments at the same migration_version with different SQL = silent schema divergence.

Diff

  • migrations/003_oauth_clients.up.sql — removed the CREATE TABLE oauth_tokens block and its four CREATE INDEX statements (idx_oauth_tokens_jti, _client_id, _expires_at, _tenant). Header comment updated.
  • migrations/003_oauth_clients.down.sql — removed the corresponding DROP INDEX / DROP TABLE statements.

Net: 2 files changed, 1 insertion(+), 36 deletions(-).

Verified

$ grep -rn "oauth_tokens" --include="*.go" .
$ grep -rn "OauthToken\|OAuthToken" domain/ internal/

Zero hits in either. No Go domain model binds to the table; no repository references it.

Test plan

  • go vet ./... — clean
  • Full integration suite green ~10s. Migrations run fresh in the testcontainer on every test run, so this exercises the trimmed 003 end-to-end (no oauth_tokens is ever created).

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes the unused oauth_tokens table and its associated indexes, providing both an upgrade and a rollback migration. Feedback indicates that the up migration contains redundant DROP INDEX statements since PostgreSQL's DROP TABLE automatically removes associated indexes. Additionally, the down migration includes a redundant index on the jti column, which is already covered by a UNIQUE constraint.

Comment thread migrations/015_drop_oauth_tokens.up.sql Outdated
Comment thread migrations/015_drop_oauth_tokens.down.sql Outdated
@saucam
Copy link
Copy Markdown
Contributor

saucam commented May 6, 2026

@rsharath can we just drop these directly without adding a new migration ?

Remove the never-wired oauth_tokens table directly from the migration
that originally created it, instead of layering a separate drop
migration on top.

Why this is safe — and would NOT be safe in general:

- Migration files become append-only the moment any deployment runs
  them, because schema_migrations.version says "this version was
  applied" while the actual rows behave however the contemporaneous SQL
  dictated. Two deployments at the same migration_version with
  different SQL = silent schema divergence.
- Per saucam's review on the prior approach: ZeroID has not been
  deployed to any persistent environment yet (no production, no
  long-lived dev). Every install runs migrations from scratch on the
  current SQL, so editing 003 in place produces the same end state
  everywhere.
- Once a real deployment exists, future cleanups of unused tables
  must use the layered-migration pattern instead.

Diff is minimal:
  003_oauth_clients.up.sql   — remove the CREATE TABLE oauth_tokens
                               block + four CREATE INDEX statements.
  003_oauth_clients.down.sql — remove the corresponding DROP INDEX /
                               DROP TABLE statements.

Verified before edit (zero hits):
  grep -rn "oauth_tokens" --include="*.go" .
  grep -rn "OauthToken\|OAuthToken" domain/ internal/

## Test plan

- [x] go vet ./... clean
- [x] Full integration suite green ~10s (migration runs fresh in the
      testcontainer on every test run, so this exercises the trimmed
      003 end-to-end).

Replaces the earlier 015_drop_oauth_tokens migration approach;
015 was reverted along with the original commit.
@rsharath rsharath force-pushed the drop-unused-oauth-tokens-table branch from 9fae4c6 to 8915786 Compare May 6, 2026 04:01
@rsharath rsharath changed the title fix: drop unused oauth_tokens table (closes #97) fix: drop unused oauth_tokens table from 003 (closes #97) May 6, 2026
@rsharath
Copy link
Copy Markdown
Contributor Author

rsharath commented May 6, 2026

You're right — I had the wrong context. Reversed the previous decision and pushed the cleaner approach (8915786):

  • Reverted 015_drop_oauth_tokens.{up,down}.sql.
  • Edited 003_oauth_clients.{up,down}.sql directly to remove the oauth_tokens block.

Net diff: 2 files changed, 1 insertion(+), 36 deletions(-) — smaller and clearer.

Caveat written into the commit message: this only works because no deployment has run 003 yet. Once a real deployment exists, the same cleanup would need a layered drop migration to avoid schema divergence (two deployments at migration_version=3 with different SQL produce silent disagreement).

Title + body updated to reflect the new approach. CI re-running.

@rsharath rsharath merged commit 55c0d84 into main May 6, 2026
10 checks passed
@rsharath rsharath deleted the drop-unused-oauth-tokens-table branch May 6, 2026 04:04
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: drop unused oauth_tokens table

5 participants