# Base Snapshot

- Human documentation: [https://docs.univer.ai/guides/bases/model/base-snapshot](https://docs.univer.ai/guides/bases/model/base-snapshot)

- Agent Markdown: [https://docs.univer.ai/guides/bases/model/base-snapshot.md](https://docs.univer.ai/guides/bases/model/base-snapshot.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [bases/model/base-snapshot.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/bases/model/base-snapshot.mdx)

---

## IBaseSnapshot

`IBaseSnapshot` is the persistence format used by Univer Bases. It describes one Base unit, including tables, table order, schema version, timestamps, and optional revision metadata.

### Properties

| Property      | Type                               | Description                                                          |
| ------------- | ---------------------------------- | -------------------------------------------------------------------- |
| id            | `string`                           | Unique id of the Base unit.                                          |
| name          | `string`                           | Base name.                                                           |
| schemaVersion | `number`                           | Snapshot schema version.                                             |
| tables        | `Record\<string, ITableSnapshot\>` | Tables keyed by table id.                                            |
| tableOrder    | `string[]`                         | Ordered list of table ids.                                           |
| createdAt     | `number`                           | Creation timestamp.                                                  |
| updatedAt     | `number`                           | Update timestamp.                                                    |
| createdBy?    | `string`                           | Creator id.                                                          |
| rev?          | `number`                           | Optional revision value used by persistence or collaboration layers. |

## Minimal snapshot

```ts
const baseSnapshot = {
  id: 'base-1',
  name: 'Product tracker',
  schemaVersion: 1,
  tableOrder: ['tasks'],
  tables: {
    tasks: {
      id: 'tasks',
      name: 'Tasks',
      primaryFieldId: 'title',
      fieldOrder: ['title', 'status'],
      fields: {
        title: { id: 'title', name: 'Title', type: 'text', config: {} },
        status: { id: 'status', name: 'Status', type: 'singleSelect', config: {} },
      },
      recordOrder: ['rec-1'],
      records: {
        'rec-1': {
          id: 'rec-1',
          values: { title: 'Write docs', status: 'In progress' },
          orderKey: 'a0',
          createdAt: Date.now(),
          updatedAt: Date.now(),
        },
      },
      views: {},
      viewOrder: [],
    },
  },
  createdAt: Date.now(),
  updatedAt: Date.now(),
}
```

## Usage

`IBaseSnapshot` is mainly used to:

1. Create a `UniverInstanceType.UNIVER_BASE` unit.
2. Persist and restore structured data.
3. Prepare data for server-side processing.
4. Transfer data between collaboration and import/export services.

> [!WARNING]
> Snapshot objects are persistence data. After a Base is running, prefer Facade APIs instead of mutating the snapshot object directly.

## Save and restore

Use Facade `save()` to include registered plugin resources, such as dashboards and local comments. `saveToBackend` below is your application's persistence function:

```ts
const base = univerAPI.getActiveBase()
if (!base) throw new Error('Open a Base first')
await saveToBackend(base.save())
```

In a new editor instance, register the same plugins before restoring with `univerAPI.createBase(savedSnapshot)`. Do not save only `tables` or mutate the live model snapshot directly.
