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:
-- Required once before changes occur
SHAPE BUCKET staff AUDITEDIf 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:
-- 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
| Variant | CleaveQL Syntax |
|---|---|
| Relative Time | REWIND "staff:a" TO "10 minutes ago" |
| Yesterday | REWIND "staff:a" TO "yesterday" |
| ISO Datetime | REWIND "staff:a" TO "2026-10-05 14:30" |
| Unix Timestamp | REWIND "staff:a" TO "1791191933" |
| Current Live State | REWIND "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:
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.
