Skip to content

Local dev database via Docker Compose (npm run db:up / db:down)#416

Open
QuentinFrc wants to merge 1 commit into
hunvreus:mainfrom
QuentinFrc:feat/dev-db-compose
Open

Local dev database via Docker Compose (npm run db:up / db:down)#416
QuentinFrc wants to merge 1 commit into
hunvreus:mainfrom
QuentinFrc:feat/dev-db-compose

Conversation

@QuentinFrc

@QuentinFrc QuentinFrc commented Jul 13, 2026

Copy link
Copy Markdown

What

Replaces the manual docker run command from the README's quick start with a small Docker Compose setup and committed development defaults:

  • npm run db:up / npm run db:down — starts/stops the local Postgres. The compose file uses a named volume (data survives restarts, unlike a re-created container), and a healthcheck with --wait so db:up only returns once Postgres actually accepts connections.
  • .env.development (committed, no secrets) — the local database credentials, host port, and a matching DATABASE_URL. The compose file injects it into the container via env_file, and Next.js picks it up automatically in development, so .env.local only needs the actual secrets (BETTER_AUTH_SECRET, CRYPTO_KEY). Anything can still be overridden in .env.local, which takes precedence and stays untracked.
  • db/envConfig.ts — passes the dev flag to loadEnvConfig so drizzle-kit (db:migrate, db:generate) also reads .env.development outside production. Production behavior is unchanged (NODE_ENV=production keeps loading in production mode).
  • npm run db:studio — browse the database with Drizzle Studio; works out of the box thanks to the above.

Why

The current quick start asks contributors to copy a long docker run command and duplicate the connection string into .env.local. With this change the database steps become npm run db:up, and .env.local shrinks to the two secrets. Data also persists across restarts, and db:up returning "ready" removes the race where migrations run before Postgres is up.

Docs

Companion docs update for the Install locally, Database and Environment variables pages: hunvreus/pagescms-website#20

Replaces the manual docker run command from the README with a small
compose file plus committed development defaults:

- docker-compose.development.yml: named volume so data survives
  restarts, healthcheck + --wait so db:up returns once Postgres is
  ready. Container credentials are injected from .env.development
  (env_file); the host port comes from DB_PORT (${DB_PORT:?} fails
  with a hint when the file is not passed).
- .env.development (committed, no secrets): Postgres credentials, host
  port and a matching DATABASE_URL, so .env.local only needs the
  secrets. Overridable via .env.local, which takes precedence and
  stays untracked.
- db/envConfig.ts: pass the dev flag to loadEnvConfig so drizzle-kit
  also picks up .env.development outside production.
- db:studio script to browse the database with Drizzle Studio.
QuentinFrc added a commit to QuentinFrc/pages-cms-website that referenced this pull request Jul 13, 2026
Matches hunvreus/pagescms#416: the local database now starts via
Docker Compose (npm run db:up), DATABASE_URL defaults to the local
Docker database through the committed .env.development, and Drizzle
Studio is available via npm run db:studio.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant