Schema
What schema.sql declares for sharing, and what the compiler creates from it. For a replicated table t, the rewrite adds the replication columns, a key, the triggers that make it append-only, and the views below. Why it works this way: Why rows never change.
Markers
-- dai:replicated
Where: In schema.sql, directly above a CREATE TABLE, with only whitespace between.
Does: Makes that table replicated: append-only, merged by union, read through t_current.
-- dai:profile session max_parties=N close=any|creator
Where: In schema.sql, any line comment (not inside a string or a block comment). close is optional and defaults to any.
Does: Makes the document a session document: every replicated row carries a session, and only members' rows are admitted.
Views and system tables
t_current
Applies to passable, session. One row per live entity: the latest version, with your columns, the _r_ columns, and _r_conflicted (1 when the entity has more than one current version). In a session document, only admitted rows.
Read this for everything the application shows.
t_conflicts
Applies to passable, session. One row per entity edited concurrently on two copies: _r_entity, heads (how many versions), head_ids.
Read this to list what needs a person's decision.
t_heads
Applies to passable, session. Every current version of every entity, including a deleted entity's tombstone. In a session document, only admitted rows.
Read this only to show the competing versions of a conflicted entity.
t
Applies to passable, session. Every row ever written, superseded and deleted ones included, and — in a session — non-member and late rows.
Never read it for display or logic. Never write to it.
_dai_replica
Applies to passable, session. This copy's own identity: id (16 bytes), seq, lc, label. One row once this copy has written anything or arrived from somebody else; empty in a brand-new document before its first write, so read it as possibly absent.
SELECT lower(hex(id)) AS id FROM _dai_replica — this copy's replica id.
_dai_seat_current
Applies to session. The seats the creator minted: seat, and _r_session. _r_replica is the creator.
Who created a session, and which seats exist.
_dai_binding_current
Applies to session. The seats joiners bound: seat, _r_session; _r_replica is the joiner.
Which seat is open (minted, not bound) and which is contested (bound by more than one replica).
_dai_member
Applies to session. session, replica: the replicas admitted to each session — each binds a minted seat that exactly one replica binds.
Whether this copy may write in a session.
_dai_close_current
Applies to session. The close of each closed session: one row per replica the closer had seen, with its highest seq.
Whether a session is closed: any row for it.