Skip to content

Add :read-only option to init-db! - #22

Open
sundbp wants to merge 1 commit into
andersmurphy:masterfrom
sundbp:init-db-read-only
Open

Add :read-only option to init-db!#22
sundbp wants to merge 1 commit into
andersmurphy:masterfrom
sundbp:init-db-read-only

Conversation

@sundbp

@sundbp sundbp commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Motivation

Read-only tooling (reports, reconciliation jobs, migration linters) wants a hard mechanical guarantee that nothing can write to a live database. Today init-db! always opens the writer pool with SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, so a caller that never issues writes is only safe by convention, and passing {:read-only true} to init-db! is silently ignored.

Change

  • init-db! accepts a top-level :read-only option. When true, every connection — the writer pool included — opens with SQLITE_OPEN_READONLY, so writes through any connection fail at the SQLite level.
  • Read-only connections skip the :journal_mode and :page_size pragmas: setting either can require a database header write (WAL conversion, page size on an empty database), which fails on a read-only connection. This also fixes a pre-existing limitation: the read-only reader pool could not open a rollback-journal database because the default journal_mode=WAL pragma threw during pool construction.
  • pragma->set-pragma-query gains a 2-arity that takes the read-only flag; the existing 1-arity is unchanged.

Verification

bb test: 21 tests, 78 assertions, 0 failures (two new tests: read-write rejection through the read-only writer pool, and read-only open of a rollback-journal database).

@sundbp
sundbp force-pushed the init-db-read-only branch from 9c0cdea to 3aa68a5 Compare August 17, 2026 16:20
Every connection, the writer pool included, opens with
SQLITE_OPEN_READONLY when :read-only is true, so writes through any
connection fail at the SQLite level.

Read-only connections skip the :journal_mode and :page_size pragmas:
setting either can require a database header write (WAL conversion,
page size on an empty database), which fails on a read-only connection.
This also lets the existing read-only reader pool open rollback-journal
databases, which previously failed during pool construction.
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