Manages declarative schema (DEFINE ... OVERWRITE, re-applied at startup) and imperative migrations (versioned, checksummed, one-shot) for SurrealDB 3+.
Features
- Manifest-driven —
manifest.tomldefines namespace, database, and schema modules with dependency ordering - Distributed lock — Shedlock-style leader election via
leader_locktable (60s expiry, scope-parameterized) - Checksum validation — SHA-256 integrity checks prevent modified migrations from being re-applied
- Dry-run / plan mode — preview what will be done before applying
- Schema snapshot —
generated/current.surqlfor CI verification - Changelog — audit trail of all applied migrations and schema modules in
_systemDB - Function validation — verify all
fn::*exist in database after schema apply
Project structure
surql/
├── manifest.toml # namespace, database, module config
├── schema/ # DECLARATIVE (re-applied with OVERWRITE)
│ ├── _shared/
│ │ └── analyzers.surql
│ └── entity/
│ ├── table.surql
│ ├── indexes.surql
│ └── fn.surql
├── migrations/ # IMPERATIVE (one-shot, versioned)
│ ├── v001_initial_seed.surql
│ └── v002_backfill.surql
└── generated/
└── current.surql # auto-generated schema snapshot
manifest.toml
[]
= "myapp"
= "main"
= "_system"
= ">=3.0.0"
[[]]
= "_shared"
= "schema/_shared"
[[]]
= "entity"
= "schema/entity"
= ["_shared"]
Library usage
use any;
async
CLI
# Install
# Preview changes (dry-run)
# Apply migrations + schema
# Generate schema snapshot
# Check snapshot is up to date (CI)
# Validate functions exist in database
Startup sequence
- Connect to SurrealDB
USE NS {ns} DB {system_db}- Bootstrap
_systemtables (migration_lock,leader_lock,shedlock,changelog) - Acquire distributed lock
- Run pending imperative migrations (checksummed)
USE NS {ns} DB {db}- Apply declarative schema modules (in dependency order)
- Validate all
fn::*exist - Release lock
Testing
# Unit tests (instant, no DB)
# Integration tests with Docker (testcontainers)
# Full CI
License
Apache-2.0