oficina / alta Public

Clone
git clone https://amadan.net/oficina/alta

Plain git — no account needed to clone.

Download

Download this file

1-- The adoption journal (existing-team adoption, CARLOS half). Every
2-- payload is AEAD under ALTA_DEK, sealed under the purpose
3-- alta/adopt/<table>/<key>, so a row copied to another key does not open.
4-- Payloads carry vd1: digests, cv1: versions, the two agent keys' values
5-- and Home's stream heads: none of them is ever stored in the clear.
6
7-- Home's state before a phase: 'pre-initialize' or 'pre-plan-a'.
8CREATE TABLE adopt_home_preflights (
9 phase TEXT PRIMARY KEY CHECK (phase IN ('pre-initialize', 'pre-plan-a')),
10 sealed BLOB NOT NULL
11) STRICT;
12
13-- One baseline per app, captured once and never rebaselined.
14CREATE TABLE adopt_baselines (
15 app TEXT PRIMARY KEY,
16 sealed BLOB NOT NULL
17) STRICT;
18-- INSERT OR REPLACE deletes without firing a delete trigger, so a second
19-- insert for an app is refused before conflict resolution can run.
20CREATE TRIGGER adopt_baselines_once BEFORE INSERT ON adopt_baselines
21WHEN EXISTS (SELECT 1 FROM adopt_baselines WHERE app = NEW.app)
22BEGIN
23 SELECT RAISE(ABORT, 'adopt: a baseline is captured once');
24END;
25CREATE TRIGGER adopt_baselines_no_update BEFORE UPDATE ON adopt_baselines
26BEGIN
27 SELECT RAISE(ABORT, 'adopt: a baseline is never rebaselined');
28END;
29CREATE TRIGGER adopt_baselines_no_delete BEFORE DELETE ON adopt_baselines
30BEGIN
31 SELECT RAISE(ABORT, 'adopt: a baseline is never deleted');
32END;
33
34-- Per app: the write (sent, landed, stopped), its rollback, the after
35-- snapshot and Paul's witness. Each is the latest state for its app.
36CREATE TABLE adopt_writes (
37 app TEXT PRIMARY KEY,
38 sealed BLOB NOT NULL
39) STRICT;
40
41CREATE TABLE adopt_rollbacks (
42 app TEXT PRIMARY KEY,
43 sealed BLOB NOT NULL
44) STRICT;
45
46CREATE TABLE adopt_afters (
47 app TEXT PRIMARY KEY,
48 sealed BLOB NOT NULL
49) STRICT;
50
51CREATE TABLE adopt_witnesses (
52 app TEXT PRIMARY KEY,
53 sealed BLOB NOT NULL
54) STRICT;
55
56-- The live checks' outcomes, every one kept: a check that ever failed
57-- keeps Plan C refused. Names and outcomes are fixed codes: passed,
58-- inconclusive, or failed:<code>.
59CREATE TABLE adopt_checks (
60 id INTEGER PRIMARY KEY,
61 name TEXT NOT NULL,
62 outcome TEXT NOT NULL CHECK (outcome IN ('passed', 'inconclusive') OR outcome GLOB 'failed:[a-z]*')
63) STRICT;
64