Restore

Restore enables applications to revert to a previous state using any change set ID, providing a powerful safety net for users. This is especially useful when working with AI agents, as it provides a way to recover from unintended changes.

Restore

Examples

Restore to the last change set

import { openLix } from "@lix-js/sdk";
// Get the most recent change set from the history
const lastChangeSet = await lix.db
  .selectFrom("change_set")
  .select(["id", "metadata"])
  .executeTakeFirstOrThrow();

// Restore the repository to that change set
await restore({ lix, to: lastChangeSet.id });

console.log("Restored to most recent change set:", lastChangeSet.id);

Create and use a checkpoint

import { openLix } from "@lix-js/sdk";

// Get the most recent change set from the history
const lastChangeSet = await lix.db
  .selectFrom("change_set")
  .select(["id", "metadata"])
  .executeTakeFirstOrThrow();

// Restore the repository to that change set
await restore({ lix, to: lastChangeSet.id });

console.log("Restored to most recent change set:", lastChangeSet.id);
// Later, you can easily find and restore to that checkpoint
const checkpoints = await selectCheckpoints({ lix });
const results = await checkpoints.execute();

if (results.length > 0) {
  await restore({ lix, to: results[0].id });
  console.log("Restored to checkpoint:", results[0].name);
} else {
  console.log("No checkpoints available");
}