Skip to content

feat: replace SQLite with Postgres via Apple Container#35

Merged
mroderick merged 8 commits into
mainfrom
feature/postgres-test-container
Jun 21, 2026
Merged

feat: replace SQLite with Postgres via Apple Container#35
mroderick merged 8 commits into
mainfrom
feature/postgres-test-container

Conversation

@mroderick

@mroderick mroderick commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

In upcoming work I was seeing more and more branching, that made it clear that running tests in SQLite would just add more overhead and problems, than the benefits it provides.

Hence, this PR :smiling:

Summary

Replace SQLite with PostgreSQL running in an Apple Container for tests and local development.

Changes

  • Container lifecycle: scripts/container.sh manages a Postgres:16-alpine container (start/stop/status/logs/ensure). test/helpers/container.js verifies prerequisites on startup.
  • Auth module: src/auth.js always uses pg.Pool — SQLite branches removed. Config defaults to local container Postgres.
  • Test isolation: getTestInstance(t) creates a per-test Postgres schema with auto-teardown via t.teardown(). All 6 test files updated to pass t and use pool.
  • Health handler: Simplified to Postgres-only queries. Health test fakes use .query().
  • Docs: All SQLite references removed from AGENTS.md, README.md, docs/development.md. .envrc-dist updated.
  • npm scripts: Auto-ensure container on dev, test, db:generate, db:migrate.

Testing

  • 98 tests passing on HEAD, 99 on parent commits
  • Each commit independently passes tests
  • .taprc uses jobs: 1 for reliability with shared Postgres database

Local Setup

  1. Install Apple Container: brew install container
  2. container system start
  3. npm ci && npm run db:generate && npm run db:migrate && npm run dev
  4. See docs/development.md for details

Related

Closes the SQLite-to-Postgres migration.

@mroderick mroderick force-pushed the feature/postgres-test-container branch from cd427b4 to 6455561 Compare June 18, 2026 14:33
- Rewrite test helper with per-test Postgres schema isolation
- Update all test files to pass t context and use pool
- Simplify health handler to Postgres-only queries
- Update health test fakes to use .query() instead of .prepare()
- Run tests serially (jobs: 1) for reliability with shared Postgres DB
- Update envrc, docs, and remove SQLite artifacts
@mroderick mroderick force-pushed the feature/postgres-test-container branch from 7c8a1b9 to e119d59 Compare June 18, 2026 14:57
@mroderick mroderick marked this pull request as ready for review June 18, 2026 15:00
@mroderick mroderick requested a review from till June 18, 2026 15:00
Comment thread scripts/container.sh Outdated
Address review feedback: the container previously had no data volume,
so every stop/start destroyed the database.

- Mount named volume auth-dev-pg-data for /var/lib/postgresql/data
- stop now only stops the container (data survives)
- New destroy command wipes container + volume explicitly
- start reuses stopped containers instead of recreating
- status distinguishes running/stopped/not-created
- Keep Postgres-only approach (removes SQLite as per PR intent)
- Preserve SSL config and error handler from main
- Remove duplicate db declaration
CI Postgres service does not support SSL. Only enable SSL for
non-localhost connections (e.g. Heroku production).
@mroderick mroderick force-pushed the feature/postgres-test-container branch from ed239ba to ea91806 Compare June 21, 2026 11:46
@mroderick mroderick requested a review from till June 21, 2026 12:02

@till till left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably squash this into one or two commits. But that's just my preference.

Other lgtm

@mroderick mroderick merged commit b11bb36 into main Jun 21, 2026
6 checks passed
@mroderick mroderick deleted the feature/postgres-test-container branch June 21, 2026 12:30
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.

2 participants