Repository navigation
Description
Overview
packages/core/src/db/migrations/ implements a five-step versioned migration ladder (v001…v005, 942 lines including the runner) plus a PRAGMA user_version ratchet and a pre-migration backup system. Every part of that apparatus exists to carry an existing database created by an older build across a schema change. NodeSpace has zero users, zero production deployments, and zero releases, so no such database exists — a fresh database is the only kind there is.
The result is that a brand-new database today executes five migrations in sequence (including one that rewrites rows that cannot exist) to arrive at a shape a single CREATE TABLE batch could produce directly.
CLAUDE.md carves out this directory as legitimate, and that carve-out is correct as written: "a fresh database still needs its schema created, so that runner is legitimate and stays." But it licenses creating the tables — not replaying five historical versions to get there, and not the version ratchet and backup machinery layered on top. The carve-out has been read more broadly than it states.
Problem Statement
Three concrete costs, all observed rather than hypothetical:
1. It teaches the banned pattern. v004_schema_relationship_edges.rs is a genuine data migration — it reads properties.relationships JSON off existing schema nodes, converts each declaration to a relationship row, and strips the key. That is exactly what the no-data-migration policy prohibits; it survives only because it shipped before the rule was enforced. Because it is the most recent structural change to the relationship table, it is now cited as the precedent to imitate: #2638's Technical Specifications name it as the model migration to follow. Following it faithfully would mean writing a backfill, and #2638 only avoids that because it separately says not to. The ladder actively propagates the prohibited pattern to the next author who reads it.
2. Migrations carry compatibility workarounds for states that cannot occur. v002_embedding_origin.rs's module doc:
"Column-existence check: this migration shipped, as an ad-hoc idempotent check outside
user_versiontracking, before the migration runner existed. A database that already applied it under the old code hasoriginpresent butuser_versionstill at 0 (never set), so this migration must tolerate running against a DB where its own effect already happened."
This is defensive code for a database shape produced by a build that no user ever ran.
3. Load-bearing code asserts a premise that is false under current policy. SqliteStore::backfill_fts_if_stale (packages/core/src/db/sqlite_store/mod.rs) documents itself as:
"any node predating the FTS table (user DBs are never reset — same reason the migration runner exists)"
"User DBs are never reset" is the opposite of the project's actual stance ("change the format and reset the database"). The FTS backfill's stated justification does not hold.
Proposed Solution
Replace the ladder with a single current-shape schema bootstrap.
- Add
packages/core/src/db/schema.rsexposing onecreate_schema(conn)that executes the current, final DDL for every table and index in one batch. - Delete
v001_initial_schema.rs…v005_conflict_journal.rsandmigrations/mod.rs. - Delete the version ratchet:
PRAGMA user_versiontracking,LATEST_VERSION,run_up_to,apply_migration,migration_name, and the newer-than-supported guard. - Delete the backup system:
backup_before_pending_migrations,db_has_data,prune_backups,MAX_BACKUPS, and theVACUUM INTOsnapshot path. - Update the two call sites in
packages/core/src/db/sqlite_store/mod.rs(SqliteStore::new's backup call,initialize_schema'smigrations::run) to callcreate_schemadirectly. - Rewrite
packages/core/tests/migrations_test.rsagainst the bootstrap: the meaningful assertions become "a fresh database gets the full current shape" and "bootstrap is idempotent," not "v1 upgrades to v5." - Carry the current shape forward faithfully, including every column and index each migration added (
embedding.originand the rebuiltidx_emb_modifiedfrom v002; v003's partial expression indexes; v005'sconflict/conflict_participanttables and their FK/cascade semantics). The schema produced must be byte-equivalent in effect to what the ladder produces today. - Re-evaluate
backfill_fts_if_stalein light of its now-void justification. It may still be wanted for in-session index repair, but its "user DBs are never reset" rationale must be corrected or the code removed. Decide and document during implementation. - Update
CLAUDE.md's DDL carve-out paragraph to point at the new bootstrap path and to state plainly that the project has no migration ladder.
Architecture Impact
No ADR mandates a versioned migration ladder. ADR-070 (../nodespace-docs/decisions/070-schema-relationship-declarations-are-edges.md) governs what the relationship table owns, not how the schema is created. This change is consistent with the pre-release stance in CLAUDE.md, and narrows a carve-out that has been read past its own wording.
If NodeSpace later ships to real users, a migration runner can be reintroduced at that point, against the schema as it exists then — which is a smaller and better-informed job than maintaining one now against a history nobody has.
Acceptance Criteria
-
packages/core/src/db/schema.rscreates the complete current schema in one batch -
v001…v005andmigrations/mod.rsdeleted -
user_versionratchet deleted (LATEST_VERSION,run_up_to,apply_migration,migration_name, newer-than-supported guard) - Backup system deleted (
backup_before_pending_migrations,db_has_data,prune_backups,MAX_BACKUPS) -
SqliteStore::newandinitialize_schemacallcreate_schema; no reference todb::migrationsremains anywhere - Resulting schema is equivalent to today's post-v005 shape — verified by a test that asserts the full table/column/index set, including
embedding.origin, v003's partial indexes, and v005's conflict tables - Bootstrap is idempotent: opening an existing database created by this build is a no-op
-
backfill_fts_if_stale's "user DBs are never reset" rationale corrected or the code removed, with the decision documented -
packages/core/tests/migrations_test.rsrewritten against the bootstrap -
CLAUDE.mdDDL carve-out paragraph updated - Tests pass (
bun run test:all) - Code passes
bun run quality:fix
Technical Specifications
Reference Files
packages/core/src/db/migrations/mod.rs— the 501-line runner, ratchet and backup system to deletepackages/core/src/db/migrations/v001_initial_schema.rs— base DDL; the starting point for the collapsed schemapackages/core/src/db/migrations/v002_embedding_origin.rs—embedding.origin+ rebuiltidx_emb_modified; carries a compatibility workaround to droppackages/core/src/db/migrations/v003_property_indexes.rs— partial expression indexes to fold inpackages/core/src/db/migrations/v004_schema_relationship_edges.rs— a data migration; its effect is already the current shape, so it contributes nothing to a fresh-database bootstrap and is deleted outrightpackages/core/src/db/migrations/v005_conflict_journal.rs—conflict/conflict_participanttables to fold inpackages/core/src/db/sqlite_store/mod.rs—SqliteStore::new(~line 242),initialize_schema(~line 284),backfill_fts_if_stale, and the version-guard test (~line 533)packages/core/tests/migrations_test.rs— to be rewrittenCLAUDE.md— the DDL-bootstrap carve-out paragraph
Dependencies
None. Independent of the relationship-reverse-name work, though landing this first would remove the need for a v006 migration there.
Related Issues
- Store relationship_type's reverse name as a queryable column on the relationship edge table #2638 (store reverse relationship name as a queryable column) — currently specced to add a
v006migration. If this issue lands first, that becomes a column in the bootstrap schema instead, and Store relationship_type's reverse name as a queryable column on the relationship edge table #2638's migration-shaped acceptance criterion should be restated.
Non-Goals
- Reintroducing a migration mechanism for a future shipped product — out of scope until there is one
- Changing any table's actual shape, column set, or index set — this is a restructuring of how the schema is created, and the resulting schema must be equivalent
- Revisiting the pre-release/no-backward-compatibility policy itself — this issue applies that policy, it does not reopen it
Activity
malibio commentedon Sep 17, 2026
Baseline before implementation — Frontend: 247 test files passed, 5085 tests passed (87.70s).
Store a relationship's reverse name as a queryable column (#2709)