Add schema v2 with the actions outbox and a read-only reader #26

Merged
svc-agent-writer merged 1 commit from feat/schema-v2-actions into main 2026-10-31 04:15:57 +00:00

Closes #11. The first phase 2 step (epic #7, ADR 0004 §2 and §7).

What changed

  • actions table: the outbox and audit log. Its columns are kind (draft, flag, move, undo), JSON params, token role, state, result code, inverse, undo_of and two timestamps. Three triggers enforce the ADR in the database:
    • Rows cannot be deleted.
    • The kind, params, role, undo_of and request time are fixed once queued.
    • A row settles from queued exactly once.
  • Schema version 2, upward only. The meta upsert writes the version only when the stored value is lower. 0.1.x still writes it unconditionally. After a rollback to 0.1.x, the next 0.2.0 start raises the version back to 2. The table is additive, so 0.1.x can still read a v2 file.
  • Store(path, reader=True) for mailmind api:
    • It runs no DDL and never creates the file.
    • It waits up to 60 s for the sync worker to bring the schema to v2, then fails with config_error.
    • It reads the mirror through a mode=ro connection.
    • Its one write path is enqueue_action, on its own connection.
    • The writer is unchanged for sync and check.
  • Outbox methods: enqueue_action, next_actions, finish_action (returns False once settled), get_action, list_actions, and count_actions_today (UTC day, counts requests in any state).
  • Tests:
    • The server tests now serve the app from a reader store, as mailmind api opens it.
    • CLAUDE.md now describes the store's two modes and the one-writer rule.

Checks

  • make check: lint, mypy --strict and pip-audit clean; 39 unit tests pass (7 new).
  • make test-integration: the GreenMail suite passes.
  • Tested by hand: a mode=ro open works on a WAL file with no -wal/-shm files present, and in a read-only directory.

Deploy note

On the first 0.2.0 start, api waits until sync has migrated the file. Both containers start together, and the migration is one CREATE TABLE, so the wait is short.

🤖 Generated with Claude Code

Closes #11. The first phase 2 step (epic #7, ADR 0004 §2 and §7). ## What changed - **`actions` table**: the outbox and audit log. Its columns are kind (`draft`, `flag`, `move`, `undo`), JSON params, token role, state, result code, inverse, `undo_of` and two timestamps. Three triggers enforce the ADR in the database: - Rows cannot be deleted. - The kind, params, role, `undo_of` and request time are fixed once queued. - A row settles from `queued` exactly once. - **Schema version 2, upward only.** The `meta` upsert writes the version only when the stored value is lower. 0.1.x still writes it unconditionally. After a rollback to 0.1.x, the next 0.2.0 start raises the version back to 2. The table is additive, so 0.1.x can still read a v2 file. - **`Store(path, reader=True)`** for `mailmind api`: - It runs no DDL and never creates the file. - It waits up to 60 s for the sync worker to bring the schema to v2, then fails with `config_error`. - It reads the mirror through a `mode=ro` connection. - Its one write path is `enqueue_action`, on its own connection. - The writer is unchanged for `sync` and `check`. - **Outbox methods:** `enqueue_action`, `next_actions`, `finish_action` (returns False once settled), `get_action`, `list_actions`, and `count_actions_today` (UTC day, counts requests in any state). - **Tests:** - The server tests now serve the app from a reader store, as `mailmind api` opens it. - CLAUDE.md now describes the store's two modes and the one-writer rule. ## Checks - `make check`: lint, mypy --strict and pip-audit clean; 39 unit tests pass (7 new). - `make test-integration`: the GreenMail suite passes. - Tested by hand: a `mode=ro` open works on a WAL file with no `-wal`/`-shm` files present, and in a read-only directory. ## Deploy note On the first 0.2.0 start, `api` waits until `sync` has migrated the file. Both containers start together, and the migration is one `CREATE TABLE`, so the wait is short. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The actions table is the ADR 0004 outbox and audit log: triggers keep
rows append-only and let each one settle once. The schema version now
only moves up, so a rollback image cannot lower it. The api process
opens the store as a reader: it runs no DDL, waits for the sync worker
to bring the schema to v2, reads the mirror through a read-only
connection, and writes only through enqueue_action.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.