Add schema v5: source ids, mailbox lists, versioned ids and the move change #62

Merged
svc-agent-writer merged 1 commit from feat/schema-v5 into main 2026-10-31 22:13:18 +00:00

Closes #54 (epic #51, ADR 0006 §4 to §6). IMAP rows and IMAP ids do not change.

Schema v5

  • messages.source_id, unique per account where not null, and messages.mailboxes, a JSON list.
  • source_id on changes and wakes, so a change row or a wake row can name a stable id.
  • The writer adds missing columns with ALTER TABLE and then creates the index. ADD COLUMN of a nullable column does not rewrite the table, so a large mirror upgrades at once. The reader waits for v5 as before.

Ids (ids.py, new)

  • The IMAP form is unchanged: every id that 0.4.x issued still resolves, and a test checks that.
  • The stable form encodes ~s1/<account>/<source_id>. Account ids match ^[a-z0-9][a-z0-9_-]{0,63}$, so no IMAP id can start with the tag, and the config needs no new refusal.
  • ids.lookup resolves either form. Every encode and decode in server.py now goes through ids.py. The write paths (draft_id, moved ids) keep the IMAP form until #57.

Store

  • get_by_source.
  • record_move, which moves a stable-id row in place and logs move.
  • The mail_search mailbox filter also matches any entry in mailboxes.
  • Wakes and the add and del changes carry source_id. update_flags and delete_uids are still keyed by uid. #55 adds source-keyed variants when the JMAP source needs them.

Tools and docs

  • The mail_changes docstring and the README name move and say that a move keeps the id.
  • The README now describes both id forms.
  • CLAUDE.md lists ids.py.

Tests

  • tests/test_ids.py covers:
    • the round trip of both forms;
    • forged stable ids, refused;
    • a lookup of a 0.4.0 id;
    • one row per source id;
    • the mailbox filter over a list;
    • a move that keeps the row and its id;
    • a wake that carries the stable id;
    • an end-to-end test through mail_changes, mail_read, mail_search and mail_thread.
  • The upgrade test now drops the v5 columns and checks that they come back.
  • make check passes 144 tests. make test-integration passes 8.

🤖 Generated with Claude Code

Closes #54 (epic #51, ADR 0006 §4 to §6). IMAP rows and IMAP ids do not change. **Schema v5** - `messages.source_id`, unique per account where not null, and `messages.mailboxes`, a JSON list. - `source_id` on `changes` and `wakes`, so a change row or a wake row can name a stable id. - The writer adds missing columns with `ALTER TABLE` and then creates the index. `ADD COLUMN` of a nullable column does not rewrite the table, so a large mirror upgrades at once. The reader waits for v5 as before. **Ids (`ids.py`, new)** - The IMAP form is unchanged: every id that 0.4.x issued still resolves, and a test checks that. - The stable form encodes `~s1/<account>/<source_id>`. Account ids match `^[a-z0-9][a-z0-9_-]{0,63}$`, so no IMAP id can start with the tag, and the config needs no new refusal. - `ids.lookup` resolves either form. Every encode and decode in `server.py` now goes through `ids.py`. The write paths (`draft_id`, moved ids) keep the IMAP form until #57. **Store** - `get_by_source`. - `record_move`, which moves a stable-id row in place and logs `move`. - The `mail_search` mailbox filter also matches any entry in `mailboxes`. - Wakes and the `add` and `del` changes carry `source_id`. `update_flags` and `delete_uids` are still keyed by uid. #55 adds source-keyed variants when the JMAP source needs them. **Tools and docs** - The `mail_changes` docstring and the README name `move` and say that a move keeps the id. - The README now describes both id forms. - CLAUDE.md lists `ids.py`. **Tests** - `tests/test_ids.py` covers: - the round trip of both forms; - forged stable ids, refused; - a lookup of a 0.4.0 id; - one row per source id; - the mailbox filter over a list; - a move that keeps the row and its id; - a wake that carries the stable id; - an end-to-end test through `mail_changes`, `mail_read`, `mail_search` and `mail_thread`. - The upgrade test now drops the v5 columns and checks that they come back. - `make check` passes 144 tests. `make test-integration` passes 8. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Add messages.source_id (unique per account) and messages.mailboxes, and
source_id on changes and wakes; the writer adds the columns to an older
mirror in place. Add ids.py with the IMAP id form, unchanged, and a tagged
form for sources with stable ids, and route every server id through it.
The mailbox filter matches any mailbox in a row's list, and record_move
moves a stable-id row in place and logs a move change.

Closes #54

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