document_history_updates Client SQLite table
The local update log: one row per Loro update, serving as both the history tail (restore = checkpoint + tail) and the outbound write queue.
Declared in packages/client-sdk/src/data/sqlite/schema/documentRecordSchema.ts
Description
Every locally authored update is stored once. While it waits for sync it carries an updateId (the id submitted to the server) and the version-vector metadata the submission needs; settlement clears them, leaving the row as ordinary tail history until compaction folds it into a checkpoint. Before a send, a contiguous run of queued local rows may be replaced by one merged row holding exactly their operations: the first row is updated in place (same id, createdAt and rowid, so the same queue and replay position) under a fresh updateId, and the other rows are deleted.
Invariant: compaction never deletes a queued row, so a checkpoint can cover a queued update's operations without removing it from the queue.
Columns
idtext- primary key
- nullable
Row id; tail compaction deletes by it.
app_kindtext- not null
Document scope matching
documents.local_idtext- not null
Document scope matching
documents.update_datatext- not null
Serialized Loro update payload.
origintext- not null
"local" (authored on this device) or "remote" (decrypted pulled update) for tail rows. Restores use it to advance the outgoing-delta marker across remote rows — their ops are already server-side — while a local row left behind by a crash stays below the marker so the next edit re-derives and sends it. "outbox" marks a queued update with no tail role (container metadata, whose content is its checkpoint, and full-state re-uploads after a remote reset); restores and compaction never see it and settlement deletes it.
created_attext- not null
Insertion timestamp; with
rowid, deterministic replay order.update_idtext- nullable
Present exactly while the row is queued for sync; rekeyed after a lost acknowledgement poisons the submitted id, and replaced by a fresh id when queued rows merge. An id never names two payloads.
partial_start_version_vectortext- nullable
Version vectors around a queued partial update.
partial_end_version_vectortext- nullable
Version vectors around a queued partial update.
rekey_countinteger- not null
- default 0
Durable bound on rekeys of a queued row; a merged row takes the largest count among the rows it replaces.
Indexes
document_history_updates_scope_created_idx(app_kind, local_id, created_at)document_history_updates_update_id_idx(update_id)- unique
- partial:
where "update_id" IS NOT NULL
document_history_updates_queued_scope_idx(app_kind, local_id, created_at)- partial:
where "update_id" IS NOT NULL
Queued rows only: pending counts and pending loads skip settled history.
- partial:
DDL
The statements the client runs to create this table and its indexes.
CREATE TABLE IF NOT EXISTS "document_history_updates" (
"id" TEXT PRIMARY KEY,
"app_kind" TEXT NOT NULL,
"local_id" TEXT NOT NULL,
"update_data" TEXT NOT NULL,
"origin" TEXT NOT NULL,
"created_at" TEXT NOT NULL,
"update_id" TEXT,
"partial_start_version_vector" TEXT,
"partial_end_version_vector" TEXT,
"rekey_count" INTEGER NOT NULL DEFAULT 0
);
CREATE INDEX IF NOT EXISTS "document_history_updates_scope_created_idx" ON "document_history_updates" ("app_kind", "local_id", "created_at");
CREATE UNIQUE INDEX IF NOT EXISTS "document_history_updates_update_id_idx" ON "document_history_updates" ("update_id") WHERE "update_id" IS NOT NULL;
CREATE INDEX IF NOT EXISTS "document_history_updates_queued_scope_idx" ON "document_history_updates" ("app_kind", "local_id", "created_at") WHERE "update_id" IS NOT NULL;