AgoraHub v0.2 uses checked-in Prisma migrations. Production startup runs
prisma migrate deploy and exits if a migration fails. Never use db push on
a production database.
- Create and verify a PostgreSQL backup.
- Set
DATABASE_URLto the target database. - Run
pnpm exec prisma migrate statusand confirm that it lists only the reviewed release migrations as pending. Prisma exits non-zero while migrations are pending; any failed or divergent history must be resolved before continuing. - Run
pnpm exec prisma migrate deployduring the maintenance window. - Run
./scripts/verify-migrations.sh, then verify/api/health. This strict check is intentionally post-deploy: it requires no pending migrations and zero drift fromprisma/schema.prisma.
The catch-up migration preserves legacy plaintext API keys by hashing each key with SHA-256 and retaining its first 12 characters for display before dropping the plaintext column. Existing keys remain valid.
This procedure adopts migration history; it does not perform a schema transition.
Use it only for a database that was last synchronized by the final v0.1
container's prisma db push and already matches prisma/schema.prisma exactly.
The v0.2 release datamodel is identical to that final v0.1 datamodel; v0.2 only
moves its database management from db push to checked-in migrations.
Do not use this procedure for a database that still has a plaintext ApiKey.key
column, lacks ApiKey.keyHash/ApiKey.keyPrefix, or has any other drift. Such a
database fails the mandatory diff below and must receive a separately reviewed
forward migration before v0.2 is deployed.
-
Take a restorable backup and record representative row counts.
-
Confirm that
_prisma_migrationsis absent or empty. -
Prove that the live schema already equals the release datamodel. The command must print
No difference detected.and exit0:pnpm exec prisma migrate diff \ --exit-code \ --from-url "$DATABASE_URL" \ --to-schema-datamodel prisma/schema.prisma
Exit
2means drift: stop without resolving either migration. In particular, never usemigrate resolveto conceal a plaintext-key or missing-table diff. -
Mark both existing migrations as applied, in order. This records SQL that the final v0.1
db pushschema has already materialized; it does not execute or skip an outstanding schema change:pnpm exec prisma migrate resolve --applied 20260205174650_init pnpm exec prisma migrate resolve --applied 20260810052000_catch_up_current_schema
-
Run
pnpm exec prisma migrate status,pnpm exec prisma migrate deploy, and./scripts/verify-migrations.sh. -
Recheck representative rows and API-key authentication.
The release gate exercises both paths: migrations on an empty PostgreSQL 16
database and history adoption on an exact db push schema. Do not baseline a
database with any schema difference. Resolve unexpected drift from a reviewed
backup or forward migration first.
Prisma migrations are forward-only. If deployment validation fails, stop the new application, preserve logs, and restore the pre-deployment database backup. Do not improvise a destructive down migration against production data.