-- Alta's state (team-provisioning-app.md §4). Sealed columns are AEAD -- under ALTA_DEK with a per-row purpose; nothing here is an app key, a -- CARLOS token, a roster bearer or team content. -- Every label ever used stays: labels are never reused (Paul, 2026-10-27). CREATE TABLE teams ( label TEXT PRIMARY KEY, sealed_name BLOB NOT NULL, environment TEXT NOT NULL, forked INTEGER NOT NULL DEFAULT 0 CHECK (forked IN (0, 1)), team_id INTEGER, team_sqid TEXT, epoch INTEGER, generation TEXT, owner_ref TEXT, created_at INTEGER NOT NULL ) STRICT; -- An app once in a team stays; a retired app's hostnames are dead for good. CREATE TABLE team_apps ( label TEXT NOT NULL REFERENCES teams(label), app TEXT NOT NULL, state TEXT NOT NULL CHECK (state IN ('active', 'retired')), PRIMARY KEY (label, app) ) STRICT; -- The owner's address, sealed; deleted at step 13 (§4). CREATE TABLE owner_inputs ( label TEXT PRIMARY KEY REFERENCES teams(label), sealed_address BLOB NOT NULL ) STRICT; CREATE TABLE runs ( id INTEGER PRIMARY KEY, label TEXT NOT NULL DEFAULT '', kind TEXT NOT NULL CHECK (kind IN ('initialize', 'create-team', 'add-apps', 'retire-apps')), apps TEXT NOT NULL DEFAULT '', plan_id TEXT, plan_expires_at INTEGER, state TEXT NOT NULL CHECK (state IN ('planned', 'running', 'parked', 'done', 'superseded', 'failed')), code TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL ) STRICT; CREATE INDEX runs_label ON runs(label, id); -- One row per (plan, role). The signed bytes are kept, sealed, only so a -- role that answered busy can be retried with the same plan until it -- expires; the credential role's carry the owner and go at step 13. CREATE TABLE plan_submissions ( plan_id TEXT NOT NULL, role TEXT NOT NULL CHECK (role IN ('credential', 'directory')), sealed_plan BLOB, state TEXT NOT NULL CHECK (state IN ('signed', 'pending', 'open', 'closed')), expires_at INTEGER NOT NULL, window_expires_at INTEGER, PRIMARY KEY (plan_id, role) ) STRICT; -- The state machine (§6), per team and app ('' for team-level steps), so -- a later add-apps run continues where an earlier one parked. CREATE TABLE steps ( label TEXT NOT NULL, app TEXT NOT NULL, step TEXT NOT NULL, state TEXT NOT NULL CHECK (state IN ('done', 'parked', 'failed')), code TEXT NOT NULL DEFAULT '', data TEXT NOT NULL DEFAULT '{}', updated_at INTEGER NOT NULL, PRIMARY KEY (label, app, step) ) STRICT; -- Exact signed request bytes, sealed, so a lost result is recovered by -- exact replay (and the roster bearer re-fetched, never stored). CREATE TABLE operator_requests ( id INTEGER PRIMARY KEY, role TEXT NOT NULL CHECK (role IN ('credential', 'directory')), sequence INTEGER NOT NULL, operation_id TEXT NOT NULL UNIQUE, action TEXT NOT NULL, label TEXT NOT NULL DEFAULT '', app TEXT NOT NULL DEFAULT '', purpose TEXT NOT NULL, head TEXT NOT NULL, sealed_request BLOB NOT NULL, state TEXT NOT NULL CHECK (state IN ('signed', 'committed', 'refused')), expires_at INTEGER NOT NULL, created_at INTEGER NOT NULL ) STRICT; CREATE INDEX operator_requests_purpose ON operator_requests(label, app, purpose, id); -- Per Home role: the stream position Home will accept next (§5). CREATE TABLE operator_streams ( role TEXT PRIMARY KEY CHECK (role IN ('credential', 'directory')), sequence INTEGER NOT NULL, head TEXT NOT NULL, updated_at INTEGER NOT NULL ) STRICT; -- The environments Alta owns, per its own records (§8's guard). CREATE TABLE environments ( app TEXT NOT NULL, environment TEXT NOT NULL, label TEXT NOT NULL REFERENCES teams(label), PRIMARY KEY (app, environment) ) STRICT; -- The audit: fixed event codes, never an address, key or platform value. CREATE TABLE audit ( id INTEGER PRIMARY KEY, at INTEGER NOT NULL, run_id INTEGER NOT NULL DEFAULT 0, label TEXT NOT NULL DEFAULT '', app TEXT NOT NULL DEFAULT '', event TEXT NOT NULL, detail TEXT NOT NULL DEFAULT '' ) STRICT; -- One run at a time (§8). CREATE TABLE run_lock ( singleton INTEGER PRIMARY KEY CHECK (singleton = 1), run_id INTEGER NOT NULL, acquired_at INTEGER NOT NULL ) STRICT; -- Alta's session idle clock (30 minutes; sessions' TTL is the absolute 12 h). CREATE TABLE session_seen ( token_hash TEXT PRIMARY KEY, seen_at INTEGER NOT NULL ) STRICT;