Skip to content

fix: migrate the database with the installed Better Auth - #101

Merged
mroderick merged 2 commits into
mainfrom
fix/better-auth-cli-migration
Nov 11, 2026
Merged

mroderick merged 2 commits into
mainfrom
fix/better-auth-cli-migration

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Local and CI migrations could not run, so the database schema drifted behind the app.

Problem

npm run db:migrate and npm run db:generate shell out to npx @better-auth/cli. npm stopped that package at 1.4.21 while the app runs better-auth@1.7.7, and the old planner builds SQL Postgres rejects:

error: type "oauthRefreshToken_authorizationCodeId_idx" does not exist

So migrations never applied, and the app logged a schema mismatch at startup.

Change

  • db:migrate runs scripts/migrate.js, the library-based migration the Heroku release phase already uses. It also seeds the planner OAuth client.
  • db:generate is removed. The current CLI reports schema status instead of writing SQL, and nothing read the files it produced.
  • The e2e job no longer migrates twice, and README/AGENTS.md drop the removed command.

Review notes

  • Look first at the e2e job: migrations now run once, through the app's own library instead of the CLI, so check that the seeded planner client still lands where the end-to-end tests expect it.
  • Deliberately not done: no dependency bump. Nothing references @better-auth/cli after this change.
  • test/features/oauth-provider.test.js times out on main too, so that failure is unrelated to this branch.

The db:generate and db:migrate scripts call @better-auth/cli, which is
abandoned at 1.4.21 while the app runs better-auth 1.7.7. The old CLI's
migration planner builds SQL that Postgres rejects, so schema changes
never reached the database:

  error: type "oauthRefreshToken_authorizationCodeId_idx" does not exist

db:migrate now runs scripts/migrate.js, which uses the installed library,
seeds the planner client, and is what the Heroku release phase already
runs. db:generate is removed: the 1.7 CLI reports schema status instead
of writing SQL, and nothing reads the files it used to produce.

The e2e job no longer runs migrations twice.
`db:migrate` now runs `scripts/container.sh ensure` first, so the
documented fresh-setup order (migrate, then `npm run dev`) works on a
machine that has never started the dev database. The script exits 0
where apple/container is not installed, so CI is unchanged.

AGENTS.md no longer claims local development uses SQLite. It documents
the container reset procedure, and records that `db:migrate` seeds the
planner OAuth client.
@mroderick
mroderick marked this pull request as ready for review November 11, 2026 14:28

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nicely done!

@mroderick
mroderick merged commit 9389354 into main Nov 11, 2026
7 checks passed
@mroderick
mroderick deleted the fix/better-auth-cli-migration branch November 11, 2026 14:45
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.

2 participants