ADR-0006 — Storage: one SQLite schema for Node and D1, YAML for stdio
- Status: accepted (owner, 2026-10-21, P0-13, with the P0-09 amendment on conditional writes)
- Date: 2026-10-16
- Related: P2-01, P2-02, P3-02, L-071, L-072, L-073, L-076, L-102
Context
Section titled “Context”Remote modes need durable state: instances, credentials, workspaces, grants, device tokens, OAuth state, sessions, audit rows, settings. Self-hosted Node and Cloudflare Workers must share one data model. The local stdio mode should need no database at all.
Decision
Section titled “Decision”- One relational schema in the SQLite dialect (Drizzle, pinned 0.x), shared by Node (
node:sqlite, built into Node 24) and Cloudflare D1. - One migration history: forward-only, checksummed SQL migrations embedded in the build and applied by the same runner on both runtimes (on Workers at first request, single-flight). No Wrangler migration history. A database newer than the binary is refused. One database fixture per released minor is kept and upgrade-tested.
- A runtime-neutral
Storageinterface with adapters:memory(tests),yaml(read-only, stdio),sqlite(Node),d1(Workers). Every adapter passes the same contract suite. - A generic
kvtable (key, value, expires_at) holds short-lived state on every runtime: OAuth provider records, single-use markers (taken atomically), sign-in transactions, setup links, approval records, cached client metadata. - Conditional writes are single statements (
ON CONFLICT,WHERE,RETURNING) or one D1batch(); never read-decide-write in application code. Outcomes are read fromRETURNINGrows, not affected-row counts, which differ between D1 andnode:sqliteafter cascades (amended 2026-10-21, P0-09, L-161). - SQLite files are created
0600with WAL,busy_timeoutand foreign keys on; backups are consistent and0600. - stdio mode reads configuration from environment variables or a YAML file (secrets only as
${ENV}or keychain references) and keeps no database.
Consequences
Section titled “Consequences”- Node and Workers behave the same; migrations are tested once.
- D1 limits (statement size, bound parameters, no interactive transactions) constrain query design for everyone.
- Audit and OAuth state are unavailable in stdio mode by design (write outcomes are logged to stderr there).
Evidence (P0-09, 2026-10-20)
Section titled “Evidence (P0-09, 2026-10-20)”The same STRICT schema and conditional statements ran on node:sqlite and local D1
(results §4): 13 of 14 steps identical (UNIQUE, STRICT and foreign-key errors,
optimistic UPDATE … RETURNING, capped ON CONFLICT … DO UPDATE … WHERE … RETURNING, json_extract, unixepoch).
The difference: D1’s meta.changes counts cascaded rows, so outcomes are read from RETURNING rows (L-161).
node:sqlite needs PRAGMA foreign_keys = ON per connection.
Alternatives considered
Section titled “Alternatives considered”- PostgreSQL for self-hosting: rejected for 1.0; a second dialect doubles migrations and tests.
- Workers KV for OAuth state: rejected; not transactional, and Node would need a different store.
- Drizzle 1.0 release candidates: deferred until stable (migration layout changes).
agility-bridge is an unofficial, community project. It is not affiliated with, endorsed by, or supported by Digital.ai. Digital.ai, Agility and VersionOne are trademarks of their respective owners.