Schema sources
Drizzle definitions inweb/internal/db/src/schema/ are the source of truth.
The mise run generate-sql task converts those definitions into SQL files in
pkg/mysql/schema/ for Go tooling and code generation.
Commit the Drizzle definitions and generated SQL in the same pull request.
Run the generator after every schema edit:
Apply a schema change
The schema gate creates a temporary PlanetScale branch frommain, applies the
Drizzle schema, and uses PlanetScale’s native branch diff to compare it with
production. The gate deletes this validation branch without creating a deploy
request. A scheduled cleanup job in the same workflow also deletes
leftover schema-check-* branches if a CI runner terminates before its cleanup
runs. Global workflow concurrency prevents cleanup from overlapping a schema
check.
Complete these steps for a schema change:
-
Update the Drizzle schema and run
mise run generate-sql. - Commit the Drizzle and generated SQL changes.
-
Create a PlanetScale migration branch from
staging: -
Create, review, and deploy a request from the migration branch into
staging. -
Create, review, and deploy a request from
stagingintomain. - Open or update the code pull request, then merge after the schema gate passes.
Split incompatible changes
Use separate pull requests when application and schema changes require a specific deployment order. Each pull request must leave the repository schema equal to the production schema before it merges. To remove a column safely:- Remove all application reads and writes for the column without changing the Drizzle schema.
- Merge and deploy the application change.
- Deploy the column removal through
stagingandmainin PlanetScale. - Remove the column from the Drizzle schema and generated SQL in a second pull request.
staging and
main before merging code that uses it.
Troubleshoot the schema check
The requiredDatabase Schema Gate / Compare production schema check prints
PlanetScale’s schema diff. Use that output to identify the pending production
change.
If the gate doesn’t run the comparison, confirm that the pull request changes
web/internal/db/src/schema/, web/internal/db/drizzle.config.ts, or
web/internal/db/package.json. Validation branches normally won’t be visible
after a check because CI deletes them before the job finishes.