SurrealKit
NOT FOR PRODUCTION USE | For SurrealDB v3
Manage SurrealDB migrations, seeding, and testing with ease. Inspired by Eloquent ORM's migration pattern.
Scope
This project is designed to manage SurrealDB migrations, seed, testing, and database management. It is not intended for production use and is specifically tailored for SurrealDB version 3.
If and when SurrealDB implements first-class tooling to manage migrations, seeding, and testing, SurrealKit will be deprecated in favour of the official SurrealDB tooling but intends to provide seamless transition.
Usage
Install via Cargo:
Or download a prebuilt binary from GitHub Releases (Linux, macOS Intel/Apple Silicon, Windows).
Initialise a new project:
This creates a directory /database with the necessary scaffolding
The following ENV variables will be picked up for your .env file, SurrealKit assumes you're using SurrealDB as a Web Database.
PUBLIC_DATABASE_HOSTPUBLIC_DATABASE_NAMEPUBLIC_DATABASE_NAMESPACEDATABASE_USERNAMEDATABASE_PASSWORD
A table (_migration) is generated and managed by SurrealKit on your configured database.
Team Workflow
SurrealKit now separates schema authoring, dev sync, and deploy migrations:
- Edit desired state in
database/schema/*.surql - Reconcile dev DB with auto-prune:
- Watch mode for local development:
- Generate a git-reviewed migration diff and update snapshots:
Generated migrations are written to database/migrations/*.surql.
Snapshots are tracked in:
database/.surrealkit/schema_snapshot.jsondatabase/.surrealkit/catalog_snapshot.json
To guard CI against missing migration/snapshot updates:
If prune is enabled against a shared DB, SurrealKit requires explicit override:
Seeding
Seeding will automatically run when you apply migrations. If you would like to reapply migrations, please re-apply your migrations.
Testing Framework
The runner executes declarative TOML suites from database/tests/suites/*.toml and supports:
- SQL assertion tests (
sql_expect) - Permission rule matrices (
permissions_matrix) - Schema metadata assertions (
schema_metadata) - Schema behavior assertions (
schema_behavior) - HTTP API endpoint assertions (
api_request)
By default, each suite runs in an isolated ephemeral namespace/database and fails CI on any test failure.
CLI Flags
surrealkit test supports:
--suite <glob>--case <glob>--tag <tag>(repeatable)--fail-fast--parallel <N>--json-out <path>--no-setup--no-sync--no-seed--base-url <url>--timeout-ms <ms>--keep-db
Global Config
Global test settings live in database/tests/config.toml.
Example:
[]
= 10000
= "http://localhost:8000"
[]
= "root"
Optional env fallbacks:
SURREALKIT_TEST_BASE_URLSURREALKIT_TEST_TIMEOUT_MSPUBLIC_DATABASE_HOST(used as API base URL fallback when test-specific base URL is not set)
Example Suite
= "security_smoke"
= ["smoke", "security"]
[[]]
= "guest_cannot_create_order"
= "sql_expect"
= "guest"
= "CREATE order CONTENT { total: 10 };"
= false
= "permission"
[[]]
= "orders_api_returns_200"
= "api_request"
= "root"
= "GET"
= "/api/orders"
= 200
[[]]
= "0.id"
= true
Actor Example (Namespace / Database / Record / Token / Headers)
[]
= "database"
= "app"
= "main"
= "TEST_DB_READER_USER"
= "TEST_DB_READER_PASS"
[]
= "token"
= "TEST_API_JWT"
[]
= "headers"
= { = "tenant_a" }
Permission Matrix Example
[[]]
= "reader_permissions"
= "permissions_matrix"
= "reader"
= "order"
= "perm_test"
[[]]
= "select"
= true
[[]]
= "update"
= false
= "permission"
JSON Reports for CI
Generate machine-readable output:
The command exits non-zero if any case fails.