Lix represents all data through four fundamental concepts that build upon each other:
In this example, two changes (c1, c2) serve as atomic units—enabling fine-grained diffing and cherry-picking—while the change set cs42 groups them together, signaling they belong together while preserving their individual atomicity. The commit a1 materializes this change set into state, forming a point in time that can be referenced, traversed, and compared. The version main acts as a named pointer to this commit, defining what state is currently visible.
Multiple versions can point at different commits, creating divergent histories that remain isolated until you merge them.
Here, Versions A and B share commit m1 and then diverge. Each version maintains its own pointer until you review and merge the changes.
Inspecting history means selecting a commit (or its change set) and rehydrating the state that existed there. Any commit in the DAG can be materialised even if no version currently points at it.
Lix does not persist full snapshots. Instead it stores:
When you request state, the engine walks the commit graph, gathers the change sets that are reachable from the target commit, and applies the newest change for every entity. The traversal is cached internally so queries stay fast without materialising full snapshots.
Conceptually, materialisation follows three steps:
Consider this example with two entities (e1, e2). The lineage of change sets might look like this:
The union of all change sets in the lineage is taken:
CS1 ∪ CS2 ∪ CS3 = { e1: "benn", e1: "julia", e2: "gunther" }
Filter for leaf changes, which are the latest changes for each entity:
e1, the latest change is "julia" from CS2.e2, the latest change is "gunther" from CS3.The resulting state is:
State = { e1: "julia", e2: "gunther" }
State is expressed by the commit graph. Each commit packages the change set that advanced the system and links it to earlier commits, so walking the graph tells you exactly how a piece of state came to be. Versions are simply named pointers into that graph, and moving a version pointer just selects which commit’s state is visible.
The commit graph is global, so any version can walk parents, replay change sets, and understand how another version reached its state.
Lix supports foreign key constraints to maintain referential integrity between entities.
For simplicity, Lix only allows foreign keys on entities in the same version scope, with the exception of references to changes themselves. This avoids cascading effects across versions and acknowledges that changes are versionless—they live outside the version system as the immutable source of truth tracked by commits.
| Rule | Rationale | Engine behaviour |
|---|---|---|
| 1. Version‑scoped → change | Changes live outside any version, so the reference is valid across all versions. | Validator skips the version_id = ? check when the target schema is lix_change. |
| 2. Version‑scoped → version‑scoped (same version) | Keeps each version self‑contained and makes deletes cheap. | Current logic stands: both rows must share the same version_id. |
| 3. Change → version‑scoped | Would immediately violate Rule 2. | Disallowed at schema‑registration time. |
Result: An example_entity or comment lives inside a specific version, but can freely point at any
lix_change.idwithout special handling. System metadata like commits and change-set elements stay in the global scope and follow the same rules when they referencelix_change.