Skip to content

ADR-0002: App data and pi-durable data live in separate SQLite files

  • Status: accepted
  • Date: 2026-11-12
  • Decided by: Stefan Imhoff

Context

Hotaru stores two kinds of data:

  • App data: users, sources, items, per-user state, feedback, weights, search index (FTS5). Managed with Drizzle and its migrations, on better-sqlite3, the setup Konbini uses.
  • Durable state: pi-durable’s conversations, entries, documents and tasks. Its schema belongs to the library, which uses Node’s built-in node:sqlite.

pi-durable can share a file with other tables if it gets a table prefix ({ prefix: "pi_" }). The SI-512 notes also warn that pi-durable’s API “changes without notice between releases” (1.2.0 to 1.5.2 in six weeks).

Decision

Two files in data/:

  • hotaru.db: app data, owned by Drizzle migrations. WAL mode, foreign keys on, busy_timeout set, as in Konbini.
  • durable.db: pi-durable storage, opened only through the harness.

The two are linked by ID only. A pipeline task stores the item ID, and an app row may store a task or conversation ID. No SQL joins and no transactions span both files.

Rejected alternatives

  • One file with a pi_ prefix. One backup and one file to manage, and app rows and harness state could commit in one SQLite transaction. But the file would have two schema owners. Drizzle Kit would see pi-durable’s tables as drift on every generate. A pi-durable upgrade that changes its tables would run inside our app database. And two SQLite drivers (better-sqlite3 and node:sqlite) would write the same file. The shared transaction isn’t needed either: pipeline phases already write app data as idempotent upserts, because a phase can rerun (SI-512).
  • A server database (Postgres) for the app data. It brings better concurrency and a real server. But it’s one more service on the VPS, for one user and a few hundred items a day. SQLite with FTS5 covers search. Konbini shows the setup works in production.

Consequences

  • Each file can be backed up, restored, inspected or deleted on its own. In development, deleting durable.db resets all pipeline and chat state without losing items.
  • Backups must cover both files. A restore must take both from about the same point in time. Otherwise, pipeline tasks may refer to items that don’t exist yet, so the pipeline must tolerate missing items.
  • No atomic commit across both files. The rule that makes this safe: every pipeline write to hotaru.db is an idempotent upsert (see conventions.md).
  • Two SQLite drivers in one process: better-sqlite3 for Drizzle, and node:sqlite inside pi-durable. Each opens only its own file.