opengb
opengb copied to clipboard
Need clear resolution for how to handle database drift
Motivation
When running in to database drift, Prisma prints a cryptic error without a clear resolution. Answering both yes and no will fail:
Generate runtime/
Generate deno.json
Generate module.gen.ts (currency)
Generate module.gen.ts (friends)
Generate module.gen.ts (rate_limit)
Generate module.gen.ts (tokens)
Generate module.gen.ts (users)
Generate module.gen.ts (email)
Generate module.gen.ts (auth)
Generate entrypoint.ts
Generate openapi.json
Generate meta.json
Check entrypoint.ts
Migrate Database develop (users)
Prisma schema loaded from schema.prisma
Datasource "db": PostgreSQL database "module_users", schema "public" at "host.docker.internal:5432"
- Drift detected: Your database schema is not in sync with your migration history.
The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.
It should be understood as the set of changes to get from the expected schema to the actual schema.
[+] Added tables
- User
[*] Changed the `User` table
[+] Added unique index on columns (username)
- The migrations recorded in the database diverge from the local migrations directory.
✔ We need to reset the "public" schema at "host.docker.internal:5432"
Do you want to continue? All data will be lost. … no
Reset cancelled.
error: Failed to run: prisma migrate dev --skip-generate
Failed. Found 1 error.
The solution is to run opengb db reset <module name>
. Somehow, we need to detect this specific error and add the solution
to the UserError
talking about this.
Implementation
Maybe just add the recommendation to any failure of prisma migrate dev
.