mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add automatic database migration recovery to scripts/develop (#23466)
When developers switch branches, the database may have migrations from the other branch that don't exist in the current binary. This causes coder server to fail at startup, leaving developers stuck. The develop script now detects this before starting the server: 1. Connects to postgres (starts temp embedded instance for built-in postgres, or uses CODER_PG_CONNECTION_URL). 2. Compares DB version against the source's latest migration. 3. If DB is ahead, searches git history for the missing down SQL files and applies them in a transaction. 4. If git recovery fails (ambiguous versions across branches, missing files), falls back to resetting the public schema. Also adds --reset-db and --skip-db-recovery flags.
This commit is contained in:
@@ -306,6 +306,20 @@ separate title.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Database migration mismatch after switching branches
|
||||
|
||||
If `./scripts/develop.sh` exits with a "database migration conflict" error,
|
||||
it means the database has migrations from another branch that don't exist
|
||||
on the current one. You have two options:
|
||||
|
||||
```shell
|
||||
# Roll back the mismatched migrations (preserves your dev data):
|
||||
./scripts/develop.sh --db-rollback
|
||||
|
||||
# Or wipe the database and start fresh:
|
||||
./scripts/develop.sh --db-reset
|
||||
```
|
||||
|
||||
### Nix on macOS: `error: creating directory`
|
||||
|
||||
On macOS, a [direnv bug](https://github.com/direnv/direnv/issues/1345) can cause
|
||||
|
||||
Reference in New Issue
Block a user