Skip to content

0021 postgres 18

github-actions[bot] edited this page Nov 18, 2026 · 2 revisions

Postgres 18, run with Docker Compose and tested on two databases

Status: accepted · Implementation: done · Date: 2026-11-18

From LibreLifts ADR 0032 and its as-built notes. Where Postgres is hosted in production gets its own record. Built 2026-11-18. The development Postgres listens on 5433 and the API on 3002, one above the usual, because LibreLifts has 5432 and 3001 on the same machine. The tests pass on both databases locally; CI runs the second in a job named api-postgres. No test counts queries on the server yet; that comes with sync.

Context

One Postgres database is the source of truth (0014). That leaves which version, how the API talks to it, how a developer gets one, and how the tests get one. One person works on LibreBars, and a test suite that needs a database started by hand is a test suite that is not run.

Decision

  • The database is Postgres 18.
  • The API talks to it through pg, with Drizzle on top. Only the file that starts the server knows about the connection pool; the rest of the API is handed a Drizzle database.
  • Migrations are generated by Drizzle Kit, committed, and run by a command of their own. The API does not migrate when it starts.
  • One Postgres schema per concern: auth, personal, later the catalog. Each has one file of table definitions.
  • In development, Postgres runs from a Docker Compose file in the repository, with a fixed project name.
  • The API is tested through buildApp() and inject(), on an in-process Postgres (PGlite, through Drizzle's own PGlite driver) by default, and on a real Postgres when a variable names one.
  • CI runs the API's tests on both.
  • Where the number of queries matters, a test counts them and fails above a limit.

Consequences

  • pnpm api test works on a fresh clone. Running the API needs Docker.
  • Two test databases can disagree. When they do, the real Postgres is right, and the test that showed the difference is kept.
  • The in-process database has one connection. Code that waits for a second connection while holding the first would hang there, which is also a bug worth finding.
  • A deploy has two steps: migrate, then start.

LibreBars

Clone this wiki locally