2 Commits
Author SHA1 Message Date
Steven Masley 462b474729 fix: refuse unknown built-in PostgreSQL data versions (#32489)
<!-- Authored with Coder Agents on behalf of @Emyrk -->

Refs
https://linear.app/codercom/issue/CORE-634/upgrade-embedded-postgresql-to-a-non-eol-version.
Precedes #32144.

Refuse to start built-in PostgreSQL when an existing data directory has
a missing or unsupported version, rather than letting embedded-postgres
replace its data.

- An existing `PG_VERSION` other than 13, including 18 or 19, now
returns an error without starting PostgreSQL.
- A missing marker also returns recovery guidance instead of
initializing over existing data.
- Fresh databases and existing PostgreSQL 13 databases keep their
current behavior.
- Development database recovery uses the same guard.

<details><summary>Agent context</summary>

The bundled embedded-postgres v1 library can delete an existing data
directory whose version does not match its PostgreSQL 13 binary. This
change checks the directory before invoking the library, without
changing the binary version or migrating data. Only Coder builds
containing this guard gain the protection; already-released older
binaries remain unchanged.

</details>

---

<sub>Coder Agents on behalf of @Emyrk.</sub>
2026-11-20 13:43:07 -06:00
Mathias Fredriksson 78b18e72bf 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.
2026-03-24 22:04:56 +02:00