feat(repo): SQLite builds, database picked at compile time (#79) #90

Merged
jfro merged 2 commits from feat/79-sqlite into main 2026-11-28 18:20:28 +00:00
Owner

What changed

PR #90 adds SQLite builds: LAMPLIGHTER_DB, set when the app is built, picks the adapter (Postgres stays the default), and migrations, queries, Docker and CI cover both. It also bumps ecto_sql to 3.14. Both suites pass locally and in CI (C24, C26), and the SQLite image migrates and is healthy (C25).

Fixes #79

Red, then green

  • Queries in lib/ use only SQL both Postgres and SQLite run (Postgres-only bits live in Lamplighter.Repo.SQL), and the rewritten queries return what they did on main.: bash -c 'source ~/.rmenv; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_79p mix test test/lamplighter/repo/sql_test.exs test/lamplighter/portable_queries_test.exs'
    • fails on the base (fe7f4e6): exit 1
    • passes on the branch (46893bd): exit 0
  • Under a SQLite build (LAMPLIGHTER_DB=sqlite), the app uses the SQLite adapter and the core test suite passes, with emails matched ignoring case and array columns round-tripping; on main there is no SQLite build at all.: bash -c 'source ~/.rmenv; export PATH=$HOME/.local/bin:$PATH; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite MIX_ENV=test MIX_TEST_PARTITION=_79p mix test test/lamplighter'
    • fails on the base (b43f616): exit 1
    • passes on the branch (428c773): exit 0

Checks

  • mix precommit (compile with warnings as errors, format, full test suite on Postgres) passes on feat/79-sqlite. (Upper Wolfjaw): bash -c 'source ~/.rmenv; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_79p mix precommit 2>&1 | tail -4', exit 0
  • mix precommit (warnings as errors, format check, full suite on Postgres) exits 0 on feat/79-sqlite; replaces C22, whose pipe hid mix's exit code. (Upper Wolfjaw): bash -o pipefail -c 'source ~/.rmenv; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_79p mix precommit 2>&1 | tail -4', exit 0
  • The SQLite Docker image builds from the branch, runs its migrations on a fresh /data volume, and answers /healthz with database ok. (Upper Wolfjaw): bash -c 'set -e; docker build -q --build-arg LAMPLIGHTER_DB=sqlite -t lamplighter:sqlite79 . >/dev/null; docker rm -f l79p >/dev/null 2>&1 || true; docker volume rm l79p >/dev/null 2>&1 || true; docker run -d --name l79p -p 127.0.0.1:4798:4000 -v l79p:/data -e DATABASE_PATH=/data/lamplighter.db -e SECRET_KEY_BASE=$(openssl rand -hex 48) -e PHX_HOST=localhost -e PHX_SCHEME=http lamplighter:sqlite79 >/dev/null; sleep 15; out=$(curl -s --noproxy "*" localhost:4798/healthz); echo "$out"; docker logs l79p 2>&1 | grep -c "Migrated"; docker rm -f l79p >/dev/null; docker volume rm l79p >/dev/null; echo "$out" | grep -q "\"database\":\"ok\""', exit 0
  • Forgejo CI on 428c773 passes for both matrix builds, postgres and sqlite (the full suite of 1305 tests plus the migration round trip). (Upper Wolfjaw): curl -sf -H "Authorization: token $FORGEJO_TOKEN" https://git.knope.dev/api/v1/repos/jfro/lamplighter/commits/428c773/status | jq -e '.state == "success" and ([.statuses[] | select(.status == "success") | .context] | unique | length) == 2', exit 0
  • In a fresh worktree at 428c773 I ran the full suite on Postgres (1305 pass) and under LAMPLIGHTER_DB=sqlite (1305 pass). I read the diff: the migrations keep Postgres behavior (citext, backfill and GIN index stay Postgres-only), and release.yml still triggers only on v* tags, so merging doesn't ship. Not tested: upgrading a real Postgres install, SQLite under load, arm64. (Prover): bash -c 'source ~/.rmenv; export PATH=$HOME/.local/bin:$PATH; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite MIX_ENV=test MIX_TEST_PARTITION=_p79c mix test 2>&1 | tail -3 | grep -q "1305 passed"', exit 0

Shipping it

  • Goes live when it merges: no. Merging to main only runs CI; images are built and published only when Jeremy pushes a v* tag with mise run release.
  • Undo: a revert puts it back.
  • Not tried on the real thing: An upgrade of a real existing Postgres install onto this build (only fresh test databases and rollback/migrate round trips); a long-running SQLite install under real polling load; multi-arch (arm64) SQLite image build.
  • For later: No SQLite image is published yet: release.yml still builds only the Postgres image, as asked. SQLite tests run one at a time. One local SQLite run in three hit a 100 ms render_async timeout in a LiveView test, which looks like timing, not the database. Pre-existing hex advisories on main (phoenix_live_view 1.2.12, plug 1.20.3) are worth a separate bump.

Prover

Passed (Sonnet): In a fresh worktree at 428c773 I ran the full suite on Postgres (1305 pass) and under LAMPLIGHTER_DB=sqlite (1305 pass). I read the diff: the migrations keep Postgres behavior (citext, backfill and GIN index stay Postgres-only), and release.yml still triggers only on v* tags, so merging doesn't ship. Not tested: upgrading a real Postgres install, SQLite under load, arm64.

Every command above was run by Fortysix's Basecamp itself, on the branch named.

## What changed PR #90 adds SQLite builds: LAMPLIGHTER_DB, set when the app is built, picks the adapter (Postgres stays the default), and migrations, queries, Docker and CI cover both. It also bumps ecto_sql to 3.14. Both suites pass locally and in CI (C24, C26), and the SQLite image migrates and is healthy (C25). Fixes #79 ## Red, then green - Queries in lib/ use only SQL both Postgres and SQLite run (Postgres-only bits live in Lamplighter.Repo.SQL), and the rewritten queries return what they did on main.: `bash -c 'source ~/.rmenv; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_79p mix test test/lamplighter/repo/sql_test.exs test/lamplighter/portable_queries_test.exs'` - fails on the base (fe7f4e6): exit 1 - passes on the branch (46893bd): exit 0 - Under a SQLite build (LAMPLIGHTER_DB=sqlite), the app uses the SQLite adapter and the core test suite passes, with emails matched ignoring case and array columns round-tripping; on main there is no SQLite build at all.: `bash -c 'source ~/.rmenv; export PATH=$HOME/.local/bin:$PATH; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite MIX_ENV=test MIX_TEST_PARTITION=_79p mix test test/lamplighter'` - fails on the base (b43f616): exit 1 - passes on the branch (428c773): exit 0 ## Checks - mix precommit (compile with warnings as errors, format, full test suite on Postgres) passes on feat/79-sqlite. (Upper Wolfjaw): `bash -c 'source ~/.rmenv; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_79p mix precommit 2>&1 | tail -4'`, exit 0 - mix precommit (warnings as errors, format check, full suite on Postgres) exits 0 on feat/79-sqlite; replaces C22, whose pipe hid mix's exit code. (Upper Wolfjaw): `bash -o pipefail -c 'source ~/.rmenv; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_79p mix precommit 2>&1 | tail -4'`, exit 0 - The SQLite Docker image builds from the branch, runs its migrations on a fresh /data volume, and answers /healthz with database ok. (Upper Wolfjaw): `bash -c 'set -e; docker build -q --build-arg LAMPLIGHTER_DB=sqlite -t lamplighter:sqlite79 . >/dev/null; docker rm -f l79p >/dev/null 2>&1 || true; docker volume rm l79p >/dev/null 2>&1 || true; docker run -d --name l79p -p 127.0.0.1:4798:4000 -v l79p:/data -e DATABASE_PATH=/data/lamplighter.db -e SECRET_KEY_BASE=$(openssl rand -hex 48) -e PHX_HOST=localhost -e PHX_SCHEME=http lamplighter:sqlite79 >/dev/null; sleep 15; out=$(curl -s --noproxy "*" localhost:4798/healthz); echo "$out"; docker logs l79p 2>&1 | grep -c "Migrated"; docker rm -f l79p >/dev/null; docker volume rm l79p >/dev/null; echo "$out" | grep -q "\"database\":\"ok\""'`, exit 0 - Forgejo CI on 428c773 passes for both matrix builds, postgres and sqlite (the full suite of 1305 tests plus the migration round trip). (Upper Wolfjaw): `curl -sf -H "Authorization: token $FORGEJO_TOKEN" https://git.knope.dev/api/v1/repos/jfro/lamplighter/commits/428c773/status | jq -e '.state == "success" and ([.statuses[] | select(.status == "success") | .context] | unique | length) == 2'`, exit 0 - In a fresh worktree at 428c773 I ran the full suite on Postgres (1305 pass) and under LAMPLIGHTER_DB=sqlite (1305 pass). I read the diff: the migrations keep Postgres behavior (citext, backfill and GIN index stay Postgres-only), and release.yml still triggers only on v* tags, so merging doesn't ship. Not tested: upgrading a real Postgres install, SQLite under load, arm64. (Prover): `bash -c 'source ~/.rmenv; export PATH=$HOME/.local/bin:$PATH; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite MIX_ENV=test MIX_TEST_PARTITION=_p79c mix test 2>&1 | tail -3 | grep -q "1305 passed"'`, exit 0 ## Shipping it - Goes live when it merges: no. Merging to main only runs CI; images are built and published only when Jeremy pushes a v* tag with mise run release. - Undo: a revert puts it back. - Not tried on the real thing: An upgrade of a real existing Postgres install onto this build (only fresh test databases and rollback/migrate round trips); a long-running SQLite install under real polling load; multi-arch (arm64) SQLite image build. - For later: No SQLite image is published yet: release.yml still builds only the Postgres image, as asked. SQLite tests run one at a time. One local SQLite run in three hit a 100 ms render_async timeout in a LiveView test, which looks like timing, not the database. Pre-existing hex advisories on main (phoenix_live_view 1.2.12, plug 1.20.3) are worth a separate bump. ## Prover Passed (Sonnet): In a fresh worktree at 428c773 I ran the full suite on Postgres (1305 pass) and under LAMPLIGHTER_DB=sqlite (1305 pass). I read the diff: the migrations keep Postgres behavior (citext, backfill and GIN index stay Postgres-only), and release.yml still triggers only on v* tags, so merging doesn't ship. Not tested: upgrading a real Postgres install, SQLite under load, arm64. Every command above was run by Fortysix's Basecamp itself, on the branch named.
jfro added this to the v1.4 milestone 2026-11-28 18:02:07 +00:00
Queries now use SQL that both Postgres and SQLite run (substr/length
prefixes, CAST AS TEXT, lower() LIKE ... ESCAPE, NOT EXISTS for the
latest row instead of DISTINCT ON). Array elements and the registration
lock go through Lamplighter.Repo.SQL, the one place with
database-specific SQL; only the Postgres forms exist so far.

Part 1 of #79; Postgres behaviour unchanged.
feat(repo): SQLite builds, with the database picked at compile time (#79)
All checks were successful
CI / test (postgres) (pull_request) Successful in 1m27s
CI / test (sqlite) (pull_request) Successful in 1m27s
428c77311f
LAMPLIGHTER_DB=postgres (default) or sqlite, read in config/config.exs when
the app is built, picks the Repo adapter: one build (and image) per database,
no runtime switching. Adds ecto_sqlite3 0.26 and bumps ecto_sql to 3.14.

- Repo.SQL compiles only its own database's forms: json_each for array
  elements on SQLite, and no advisory lock (SQLite transactions begin
  IMMEDIATE, so they already run one at a time).
- Migrations: users.email is NOCASE on SQLite (citext on Postgres); the jsonb
  backfill and the gin index run only on Postgres.
- Datetime and list parameters in fragments are typed, so SQLite compares
  them in its stored format; boolean helpers are parenthesized for type/2.
- Config: DATABASE_PATH for SQLite in prod; dev/test database files; tests
  run one at a time on SQLite.
- Dockerfile: --build-arg LAMPLIGHTER_DB=sqlite, with /data for the file.
- CI: the suite and a migration round trip on both databases.
- README: SQLite section and DATABASE_PATH.
jfro merged commit 025b4a43ce into main 2026-11-28 18:20:28 +00:00
jfro deleted branch feat/79-sqlite 2026-11-28 18:20:29 +00:00
Sign in to join this conversation.
No description provided.