• Start

Sync

Sync pushes your .surql schema files to SurrealDB immediately, keeping the database in desired state. Use it for local development and ephemeral environments.

Sync applies all .surql files in database/schema/ to the connected SurrealDB database in a single pass, bringing the database into alignment with your files. It tracks each file by content hash so that unchanged files are skipped on subsequent runs.

surrealkit sync --user root --pass secret

SurrealKit connects to the database, reads your schema files, applies any definitions that have changed, and removes definitions for files that have been deleted (pruning).

During active development, pass --watch to keep SurrealKit running and automatically re-sync on any file change:

surrealkit sync --watch --user root --pass secret

SurrealKit debounces rapid consecutive saves, so editing multiple files in quick succession triggers a single sync rather than many overlapping ones.

When Sync runs:

  1. All .surql files in database/schema/ are read and their content hashes computed.

  2. Hashes are compared against the __entity metadata table stored in the database.

  3. New or changed files have their SQL statements applied.

  4. Files that existed in a previous sync but are no longer present are pruned: their definitions are removed from the database.

  5. The __entity table is updated to reflect the new state.

Any definition that exists in the database but not in a file will be removed on the next sync.

Pruning is safe when you are the sole owner of the database. On a shared database (one already containing SurrealKit metadata from another developer or environment), automatic pruning could remove definitions that others have added.

SurrealKit detects this situation and refuses to prune unless you pass an explicit flag:

surrealkit sync --allow-shared-prune --user root --pass secret

Do not use this flag routinely on shared databases. Consider switching to Rollouts for any database that more than one person or service writes to.

SurrealKit creates two internal tables in the target database:

TablePurpose
__entityStores the content hash and file key for every schema definition SurrealKit manages. Used to detect changes and drive pruning.
__rolloutStores rollout state. Created when you first use Rollouts; may be present even if you use Sync only.

These tables are managed by SurrealKit and should not be modified directly.

If you are using Vite, the vite-plugin-surrealkit package integrates Sync with the dev server:

npm install --save-dev vite-plugin-surrealkit
// vite.config.ts
import { defineConfig } from 'vite';
import { surrealkitPlugin } from 'vite-plugin-surrealkit';

export default defineConfig({
plugins: [
surrealkitPlugin({
syncArgs: [],
}),
],
});

On vite dev, the plugin:

  1. Runs surrealkit sync once at startup.

  2. Watches database/schema/**/*.surql.

  3. Re-runs sync on any file change, debouncing concurrent runs.

FlagDefaultDescription
--watchoffRe-sync automatically when schema files change
--allow-shared-pruneoffPermit pruning on a database that already has SurrealKit metadata
--dry-runoffPrint what would be applied without modifying the database
--fail-fastoffStop on the first error rather than continuing

Was this page helpful?