OXYGENHUB
# c7161ec1a607 spectra / crates / spectra-core / migrations / 0001_ledger.sql
1.3 KiB · SQL · last changed The ledger: hash-chained events in the frozen envelope, signed checkpoints, admin verify, check and rebuild (#3) 2 days ago source blame history raw
1
-- The ledger (spec §9.1, §9.5): every event, in order, chained by hash.
2
-- Columns are the frozen envelope; `pruned` marks a stub whose payload and
3
-- proof were removed by `spectra admin prune` (its hash and prev stay).
4
CREATE TABLE events (
5
    seq             INTEGER PRIMARY KEY,
6
    id              TEXT NOT NULL UNIQUE,
7
    at_ms           INTEGER NOT NULL,
8
    hlc_wall        INTEGER NOT NULL,
9
    hlc_logical     INTEGER NOT NULL,
10
    prev            BLOB NOT NULL,
11
    hash            BLOB NOT NULL,
12
    auth_key        BLOB,
13
    auth_method     INTEGER NOT NULL,
14
    auth_assurance  INTEGER NOT NULL,
15
    auth_proof      BLOB,
16
    kind            TEXT NOT NULL,
17
    actor           TEXT NOT NULL,
18
    session         TEXT,
19
    project         TEXT,
20
    subject         TEXT,
21
    payload         BLOB,
22
    trace           TEXT,
23
    pruned          INTEGER NOT NULL DEFAULT 0
24
);
25
CREATE INDEX events_kind ON events(kind);
26
CREATE INDEX events_subject ON events(subject);
27
28
-- Facts about this database: the ledger format it was written with.
29
CREATE TABLE meta (
30
    key   TEXT PRIMARY KEY,
31
    value TEXT NOT NULL
32
);
33
34
-- Projection: how many events of each kind (Radar's Log header, `admin check`).
35
CREATE TABLE event_counts (
36
    kind  TEXT PRIMARY KEY,
37
    n     INTEGER NOT NULL
38
);