Skip to content

research: should perima drop SQLite migrations entirely (post-v1 reopen) #134

Closed

Description

@utof

Background

perima uses refinery 0.8 reading numbered SQL migration files (crates/db/migrations/V001..V010) for SQLite schema management via the rusqlite 0.39 driver. Pre-v1, the project has zero deployed user databases and a single solo developer; post-v1, mobile (UniFFI + Expo) and an Obsidian plugin (axum HTTP API) will share the same schema, with multi-device CRDT sync via Loro.

The question of whether to drop migrations entirely (collapsing to a single canonical idempotent schema), keep migrations as-is, or adopt a hybrid was investigated externally during Batch F design. This issue archives the findings for the post-v1 reopen point when the multi-device sync story changes the calculus.

Research recommendation: HYBRID

Keep refinery for table and index DDL; generate FTS5 trigger DDL idempotently at boot via templated codegen (no version numbers for trigger changes). Adopted by Batch F.

Key tradeoff (the deciding argument)

Multi-device CRDT sync requires a queryable schema-version oracle. When peer devices on different binary versions reconcile, they need to detect schema mismatch before exchanging mutations. refinery_schema_history's SELECT MAX(version) provides that oracle for free. A single-canonical-schema approach has no version surface — peers cannot negotiate compatibility.

This argument applies to table/index shape, which is what CRDT peers actually need to agree on. FTS5 trigger bodies are derived from table shape and do not participate in peer negotiation, so they can live outside refinery.

Evidence (with sources)

Peer projects

Lighter alternatives to refinery (for future evaluation)

Risks of the hybrid approach (to mitigate)

  1. Two schema management systems (refinery for tables/indexes, boot-time codegen for triggers). Requires inviolable rule: triggers NEVER go in refinery files; codegen is authoritative for all trigger DDL.
  2. Trigger drift detection: without rule Upgrade actions/checkout to v5 (Node 24 deprecation) #1, a trigger could exist in both systems with diverging definitions. Insta snapshot tests are the safeguard.
  3. No published prior art for this exact hybrid in Rust+SQLite — bespoke approach. Mitigated by inline documentation.
  4. Refinery squash window: collapsing V001..V0NN into a single canonical V001 is painless pre-v1 (zero live user DBs). Post-v1, the fingerprint must match every live DB's already-applied state — doable but fingerprint-fragile.
  5. Minijinja template correctness: generated SQL must be regression-tested via insta snapshots; CI must enforce snapshot freshness.

Cost of "add migrations later" for perima specifically

Zero cost today (no deployed user databases). Post-v1, a belated V001 migration must be a CREATE TABLE IF NOT EXISTS matching the schema state of every live DB. Doable but fingerprint-fragile.

When to reopen this issue

  • When mobile (UniFFI + Expo) ships and multi-device sync goes live.
  • When the FTS5 trigger codegen approach (Batch F) reveals limitations that the boot-time install pattern cannot handle.
  • If a published Rust+SQLite project demonstrates a successful migration-less approach at scale.

Activity

  1. added
    status/needs-research
    on Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/needs-research

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions