Skip to content

Experiment: Migrate local DB from SurrealDB embedded to SQLite (libsql) #1219

Closed

Description

@malibio

Goal

Validate and implement the migration of the local embedded database from SurrealDB (RocksDB backend) to SQLite via the libsql Rust driver. The cloud DB stays SurrealDB — this is a local-only change.

Motivation

  • Inspectable — DB Browser, sqlite3 CLI, and standard tooling work with SQLite files. SurrealDB embedded (RocksDB) is opaque — no dev tooling.
  • Leaner — SurrealDB embedded carries graph engine, RLS, LIVE SELECT, and query parser machinery that is irrelevant locally. Local DB has no access control — if data is in the local DB, the user has access by definition.
  • Simpler — Local operations are just CRUD + graph traversal. No SurrealQL needed. Standard SQL + WITH RECURSIVE covers everything.
  • Async-native — libsql is async-native Rust. No spawn_blocking wrappers needed (unlike rusqlite).
  • access_tags cloud-only — Local schema is clean with no ACL fields. CloudSyncService enforces what flows in and purges revoked data.

Architecture Context

Local:   libsql (SQLite file, local mode) — lean, inspectable, no ACL
Cloud:   SurrealDB (Cloud or self-hosted) — RLS, LIVE SELECT, Stamped ACL, namespace-per-tenant
Bridge:  CloudSyncService — enforces what flows between them, purges revoked data locally

CloudSyncService talks to NodeService via domain events broadcast channel — it never touches the storage layer directly. The abstraction means CloudSyncService (nodespace-sync) requires no changes for this migration.

Validation Points

Phase 1 — File format compatibility

  • Create a SQLite file via libsql local mode (no Turso sync features)
  • Confirm DB Browser for SQLite can open and read it correctly
  • Confirm sqlite3 CLI can open it
  • Confirm no WAL/SHM artifacts when app is not running

Phase 2 — Schema design

  • node table — id, type, content, properties (JSON), title, lifecycle_status, version, sync_seq, created_at, modified_at
  • relationship table — in (FK → node), out (FK → node), type, created_at (no access_tags — cloud only)
  • embedding table — node_id (FK → node), vector (BLOB), model, created_at
  • WITH RECURSIVE CTE for graph traversal (children tree, ancestor path)
  • sqlite-vec extension for HNSW vector search
  • Cascade delete: node deletion removes relationships atomically (FK + trigger or explicit transaction)

Phase 3 — NodeService implementation

  • Replace surreal_store.rs with sqlite_store.rs backed by libsql
  • Implement all NodeService storage operations: create/get/update/delete node, create/delete relationship, get_children, vector search
  • Domain event broadcast unchanged — NodeService already owns this
  • All existing NodeService tests pass against SQLite backend

Phase 4 — Performance validation

  • Basic CRUD latency vs SurrealDB embedded (hypothesis: faster, less overhead)
  • WITH RECURSIVE graph traversal for a 1000-node tree
  • sqlite-vec HNSW search across 10k embeddings

Key Decisions Already Made

  • libsql over rusqlite — async-native, no spawn_blocking, standard SQLite file format in local mode, no Turso cloud coupling needed
  • sqlite-vec over separate embedding store — keeps everything in one file, simpler ops
  • No access_tags locally — cloud-only concern. Close Stamp access_tags on relationships (local schema + NodeService) #1217.
  • Cloud DB stays SurrealDB — this migration is local-only, CloudSyncService unchanged

Success Criteria

  • DB Browser reads libsql-created SQLite file correctly (Phase 1)
  • All NodeService operations implemented and tested against SQLite
  • Graph traversal (get_children, ancestor path) correct via WITH RECURSIVE
  • Vector search works via sqlite-vec
  • All existing NodeService tests pass
  • nodespace-sync smoke test passes (CloudSyncService unaffected)

Related

Activity

  1. malibio commented on May 28, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 93 failed | 3843 passed (pre-existing persistence/layout test failures unrelated to SQLite migration)

  2. self-assigned this
    on May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions