Getting Started

Tutorial: Building with CleaveDB

REWIND — restore a document

When an erroneous update corrupts an important document, REWIND restores that document back to the exact state it had at a specified point in time, using CleaveDB's MVCC history ledger.

Prerequisite: Audited or versioned bucket

To restore earlier versions, the target bucket must have change logging enabled before the mutations occur:

CleaveQLExample · Enable audit logging
-- Required once before changes occur
SHAPE BUCKET staff AUDITED

If a bucket is not audited or versioned, CleaveDB will reject the command with: No history for 'staff:a'. Run SHAPE BUCKET staff AUDITED ....

Restoring document state

Issue REWIND with the qualified document ID (bucket:id) and target timestamp:

CleaveQLExample · Mutate and rewind document
-- Make a sequence of updates
CHANGE staff "a" SET age TO 36
CHANGE staff "a" SET age TO 37

-- Restore document state from 1 minute ago
REWIND "staff:a" TO "1 minutes ago"

-- Verify the restored document
FIND staff "a"

The fields of staff:a now match what was stored at that exact minute.

Temporal syntax variants

VariantCleaveQL Syntax
Relative TimeREWIND "staff:a" TO "10 minutes ago"
YesterdayREWIND "staff:a" TO "yesterday"
ISO DatetimeREWIND "staff:a" TO "2026-10-05 14:30"
Unix TimestampREWIND "staff:a" TO "1791191933"
Current Live StateREWIND "staff:a" TO "now"

Graph bonds survive rewinds

Unlike relational cascades that break foreign keys, CleaveDB graph bonds are decoupled from document revisions. Rewinding a document modifies its internal attributes without severing incoming or outgoing bonds:

CleaveQLExample · Bonds persist through document rewinds
BOND "staff:a" TO "staff:b" AS "pal"
CHANGE staff "a" SET age TO 50
REWIND "staff:a" TO "now"

-- The graph bond remains completely intact
FIND "pal" OF "staff:a"

Any aggregations (DISTILL) run after the rewind instantly reflect the restored document attributes.