Files
token-circles/worker/migrations/0033_seal_notes.sql
Komediruzecki b3dfcd38ff feat(encryption): seal notes, learned patterns and tag-rule criteria
Migration 0033 extends field encryption to the free text beside the
ledger: notes on accounts, savings and retirement goals, housing and
portfolio holdings, loan prepayment notes (owned through their loan),
the patterns auto-categorization learns, and tag-rule criteria. Every
write goes through sealForInsert or sealedUpdate, and every read that
reaches a client, a match or a parse goes through openRows: the
account, goal, housing, holding and loan routes, the accounts export,
the MCP goals read and tag-rule upsert, backup export and restore, and
the backfill, which finds a prepayment's owner through its loan.

A learned pattern was found by `pattern = ?`, which cannot match sealed
text. With a key the profile's mappings are opened and compared in JS,
exactly and lowest id first, as the query found them. Tag-rule criteria
are opened before they are parsed, so listTagRules and autoApplyTagRules
now take the keyring.

Edits leave out a field the body left out (sealedUpdate drops undefined
values). A retirement-goal or housing edit that omitted a field no
longer fails with a 500, and a holding edit without notes no longer
writes the stored value back, which with a key would have sealed the
ciphertext a second time.

Names stay plaintext; the plan doc records why, and what else remains.
2026-09-11 10:18:29 +02:00

13 lines
985 B
SQL

-- Field encryption, part two (migration 0033): the free text 0031 left in plaintext — notes on
-- accounts, goals, loan prepayments, housing and holdings, the patterns auto-categorization learns,
-- and tag-rule criteria. The same contract as 0031: schema only, every row starts at 0 (plaintext),
-- and nothing here reads or rewrites a value. Names stay plaintext; the plan doc says why.
ALTER TABLE accounts ADD COLUMN text_enc INTEGER NOT NULL DEFAULT 0;
ALTER TABLE savings_goals ADD COLUMN text_enc INTEGER NOT NULL DEFAULT 0;
ALTER TABLE retirement_goals ADD COLUMN text_enc INTEGER NOT NULL DEFAULT 0;
ALTER TABLE loan_prepayments ADD COLUMN text_enc INTEGER NOT NULL DEFAULT 0;
ALTER TABLE housings ADD COLUMN text_enc INTEGER NOT NULL DEFAULT 0;
ALTER TABLE portfolio_holdings ADD COLUMN text_enc INTEGER NOT NULL DEFAULT 0;
ALTER TABLE category_mappings ADD COLUMN text_enc INTEGER NOT NULL DEFAULT 0;
ALTER TABLE tag_rules ADD COLUMN text_enc INTEGER NOT NULL DEFAULT 0;