Skip to content

Auth schema follows Better Auth; migrations reset to one 0001 - #40

Merged
ryuzdev merged 2 commits into
mainfrom
better-auth-schema
Oct 24, 2026
Merged

ryuzdev merged 2 commits into
mainfrom
better-auth-schema

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Oct 24, 2026

Copy link
Copy Markdown
Member

Owner: auth tables follow Better Auth's database structure (https://better-auth.com/docs/concepts/database), and all migrations merge into one fresh 0001_init.sql; production starts from an empty database when this ships (owner-approved, single user).

Mapping (Better Auth core + api-key + oauth-provider/MCP + admin):

Old New
account user (core + admin role/banned/banReason/banExpires + Outer extras plan, planStatus, Stripe ids, graceUntil, terms, lastActiveAt)
email_code verification (identifier = 'email-verification:<email>', value = code hash, + attempts)
web_session session (token = sha256 of the cookie)
api_key apikey (key = sha256, referenceId → user, enabled, lastRequest, + client name/version)
oauth_client oauthClient (+ kind, host, verified, fetchedAt, lastTokenAt)
oauth_grant oauthConsent (+ client name/version, lastUsedAt, revokedAt)
oauth_token oauthAccessToken + oauthRefreshToken (rotatedAt keeps refresh-reuse revocation)
oauth_request kept (pending authorization has no Better Auth table)
— account, oauthClientAssertion created in Better Auth's shape, unused

agent_action, app_collaborator, usage_* now reference user. Departures from Better Auth, stated in the migration header: INTEGER-ms dates, and only hashes are stored for session tokens, verification codes, API keys and OAuth tokens (Better Auth keeps raw session tokens).

Sources: the database doc, @better-auth/core table definitions, @better-auth/api-key, @better-auth/oauth-provider schema, the admin plugin schema, and Noite's live Better Auth SQLite schema.

Behavior is unchanged: every existing auth, OAuth (CIMD/DCR, PKCE, refresh rotation and reuse revocation), MCP and console test passes with only table/column names adapted in fixtures; two bind-order bugs caught by those tests during the port were fixed. New test: a fresh DB applies 0001 and PRAGMA foreign_key_check is empty. 438 pass.

Ship plan: after tonight's M1 live checks (they use the current API key), run the reset runbook — delete apps, stop, remove outer.sqlite* and the R2 state snapshot, release, re-sync the template — then the owner reconnects ChatGPT, Claude, Gemini, Perplexity and the console.

user/session/account/verification/apikey/oauthClient/oauthConsent/
oauthAccessToken/oauthRefreshToken/oauthClientAssertion replace
account/web_session/email_code/api_key/oauth_client/oauth_grant/
oauth_token; oauth_request, beta_allowlist and waitlist stay
Outer-shaped with userId. INTEGER-ms dates and sha256-only secret
columns are documented departures. All code paths and fixtures
re-pointed; plan/quota/metrics/prune/console behavior unchanged.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 32 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b1801568-9a58-4dc5-a370-9a5aa8ef6329
Commits

Reviewing files that changed from the base of the PR and between 6f9a844 and 3963106.

Files selected for processing: 24
  • crates/outer/migrations/0001_init.sql
  • crates/outer/migrations/0002_app_cron.sql
  • crates/outer/migrations/0003_rollback_day.sql
  • crates/outer/migrations/0004_agent_action.sql
  • crates/outer/migrations/0005_agent_action_created.sql
  • crates/outer/migrations/0006_visitor_day.sql
  • crates/outer/migrations/0007_d1_migration.sql
  • crates/outer/src/apps/mod.rs
  • crates/outer/src/auth/cimd.rs
  • crates/outer/src/auth/mod.rs
  • crates/outer/src/auth/oauth.rs
  • crates/outer/src/auth/tests.rs
  • crates/outer/src/db/mod.rs
  • crates/outer/src/deploy/pipeline.rs
  • crates/outer/src/fleet/manager.rs
  • crates/outer/src/http/console.rs
  • crates/outer/src/http/proxy.rs
  • crates/outer/src/mcp/actions.rs
  • crates/outer/src/mcp/tests.rs
  • crates/outer/src/mcp/tools/mod.rs
  • crates/outer/src/moderation/gate.rs
  • crates/outer/src/observe/metrics.rs
  • crates/outer/src/ops.rs
  • crates/outer/src/secrets.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…iry/revoked checks, consent FK, strict resource

1. exchange_code/exchange_refresh require client_id (invalid_client when absent, invalid_grant on mismatch) before any state change. 2. Refresh rotation (consent-live recheck, claim, mint) and reuse revocation run in single transactions. 3. Banned (banExpires-aware) and missing users fail both grant types. 4/5. resolve_bearer enforces apikey.expiresAt and token revoked flag. 6. oauthAccessToken/oauthRefreshToken.referenceId FK to oauthConsent with cascade. 7. Token resource must equal the authorize request's (no downgrade to server default). Tests: 5 new finding-pinning tests; existing token tests send client_id.
@ryuzdev
ryuzdev merged commit d9b5f48 into main Oct 24, 2026
4 checks passed
@ryuzdev
ryuzdev deleted the better-auth-schema branch October 24, 2026 15:05
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.

1 participant