oficina / docs Public

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

Plain git — no account needed to clone.

Download

Download this file

1-- The team rung, and the revision counter and feed log the suite contract's
2-- producer half reads (spec §8.2.1 and §8.2.2; suite revision 10, suite
3-- main c38e3ad).
4--
5-- visibility: Paul's ruling, 2026-11-01, "New docs Team, old private". The
6-- column DEFAULT is 'private', and that default is the half of the ruling
7-- this migration carries: every document that exists when it runs stays
8-- private until its owner shares it. New documents are written 'team'
9-- explicitly by Store.CreateDraft; nothing relies on this default for them.
10-- The CHECK keeps the vocabulary closed, so a typo is a loud write failure
11-- rather than a third value every reader treats as private.
12ALTER TABLE documents ADD COLUMN visibility TEXT NOT NULL DEFAULT 'private'
13 CHECK (visibility IN ('private', 'team'));
14
15-- revision: a token per document, replaced in the same writer transaction
16-- as every applied update, rename, visibility change and deletion. Not
17-- doc_updates.seq, which a rename never touches although a rename changes
18-- what S3 serves. Every value is a fresh random positive int63
19-- (newRevision), here and in code, never a count and never a clock: after a
20-- restore from a backup a count or a clock issues again a value issued
21-- before, for different content, and a consumer's copy would be answered as
22-- current (Astra on oficina/docs feat/suite-producer, two rounds,
23-- 2026-11-01 — including a backup taken BEFORE this migration, restored and
24-- migrated again, which a constant here would have given the same revision
25-- it gave the first time). memoria only matches revisions for equality, and
26-- S2 decides STALE from suite_feed, so no order is needed. SQLite's random()
27-- is ChaCha20 seeded from the OS; masked to 63 bits and forced odd, so never
28-- 0 and 62 random bits (spec §8.2.2 has the probabilities).
29ALTER TABLE documents ADD COLUMN revision INTEGER NOT NULL DEFAULT 1
30 CHECK (revision >= 1);
31UPDATE documents SET revision = (random() & 9223372036854775807) | 1;
32
33-- suite_feed: append-only, one row per bump (creation included), written in
34-- the bump's own transaction, so S1 can page by id and a consumer's cursor is
35-- a position in this table. No title, no content, no visibility: the four
36-- fields suite S1 carries and a stamp, so the table holds nothing the
37-- plaintext gate (spec §12) would have to look at.
38--
39-- stamp is a random positive nonce, written once with the row. The S1
40-- cursor is "<id>.<stamp>" and the stamp is checked on every request: after
41-- a restore AUTOINCREMENT hands the same ids out again to different rows,
42-- and a bare id would carry on silently from a position that now means
43-- something else (the Fichas pattern, fichas main 7bfd4c4). Random, not a
44-- time, so a clock set back cannot reproduce one either.
45CREATE TABLE IF NOT EXISTS suite_feed (
46 id INTEGER PRIMARY KEY AUTOINCREMENT,
47 document_id INTEGER NOT NULL,
48 revision INTEGER NOT NULL,
49 gone INTEGER NOT NULL CHECK (gone IN (0, 1)),
50 touched_at DATETIME NOT NULL,
51 stamp INTEGER NOT NULL CHECK (stamp > 0)
52);
53
54-- Every live document that already exists is announced once, at its new
55-- random revision, so a consumer's first poll sees the whole library rather than only what
56-- changes after this deploy. Live is the producer's definition: not deleted,
57-- and not one of 0002_owners.sql's orphans, which nobody can read.
58-- Their stamps are random nonces like every other row's.
59INSERT INTO suite_feed (document_id, revision, gone, touched_at, stamp)
60 SELECT id, revision, 0, updated_at, (random() & 9223372036854775807) | 1
61 FROM documents
62 WHERE deleted_at IS NULL AND owner_id > 0
63 ORDER BY updated_at, id;
64