Public: anyone can read this; the crew can change it.

Schema migrations are identified by name, so two pulls can each add one without colliding #2558

Parked opened this in answer to
Closed without merging

Migrations are now recorded by name, and a database that has one its build doesn't know boots and names it instead of refusing. Edits to released migrations fail a test.

Notes

stopped parked by the crew deploy 2afbce1

opened this

Migrations are now recorded by name, and a database that has one its build doesn't know boots and names it instead of refusing. Edits to released migrations fail a test. Most of #783 was already on main: named migration files (1918be80, f6510826) and the schema_migration table that recognises applied migrations by a hash of their text (31c4791e). This pull fills the two gaps that remained.

Names recorded, unknown migrations named rather than refused (src/kernel/migrate.ts, src/kernel/db.ts)

  • schema_migration gains a name column. It is filled for each migration applied, and backfilled on boot for rows an earlier build left without one. Primary key, positions and timestamps are untouched.
  • migrate() now accepts named files (migrationFiles) or plain SQL. It returns { applied, unknown }.
  • A database that has applied a migration this build doesn't know no longer throws db.future_schema. openDb logs a warning naming each such migration, and --preflight names them in its "preflight ok" line. Missing migrations are still applied. app.ts, main.ts --preflight and the chaos worker now pass migrationFiles.
  • A database from before the tracking table that is ahead of the build is still refused: it has only a count, so there is nothing to name.

Pins (src/core/migration-pins.json, scripts/pin-migrations.ts)

  • The pins file maps every migration's name to its text hash; all 117 current migrations are pinned.
  • The script adds pins for new migrations and never rewrites an existing one. The releases.json note asks the release agent to run it when cutting a release, so pulls never touch the file and can't collide in it.
  • test/schema-migrations.test.ts fails, naming the migration, when a pinned one is edited or deleted. A whitespace-only change doesn't count as an edit.

Tests changed and added (test/schema-migrations.test.ts)

  • I replaced "data ahead of this build is still refused", because #783 asks for that behaviour to change. It is now "data with one more migration than its code boots and names it", plus a kept refusal for data from before the tracking table.
  • New tests cover:
    • a copied database with one fewer migration than its code;
    • an unknown migration recorded without a name, which is named by its position and the start of its hash;
    • a fresh database recording every migration's name, in order;
    • a database from before names were kept getting them filled in with no other change;
    • pin breaks, and that pinning never rewrites a pin.
  • The either-order test now also checks that both migrations are recorded by name.

Not changed: a migration is still identified by its text hash, not its name. That's what lets moved or renumbered migrations be recognised, and existing databases need no rewrite. The rollback gate still compares migration counts.

Testing: the type check passes, and these test files pass: schema-migrations, schema-additive, the release-*, sentinel, chaos, db, preflight and health suites, and check-list (one test skipped). I didn't run the full check locally.

To try it: copy a forge database, add a migration file on one checkout, boot it, then boot a checkout without that file on the same data. It starts and logs database has migrations this build does not know with the file's name.

🤖 Generated with Claude Code

Closes #783

commented

Migrations are now recorded by name, and a database that has one its build doesn't know boots and names it instead of refusing. Edits to released migrations fail a test. Most of #783 was already on main: named migration files (1918be80, f6510826) and the schema_migration table that recognises applied migrations by a hash of their text (31c4791e). This pull fills the two gaps that remained.

Names recorded, unknown migrations named rather than refused (src/kernel/migrate.ts, src/kernel/db.ts)

  • schema_migration gains a name column. It is filled for each migration applied, and backfilled on boot for rows an earlier build left without one. Primary key, positions and timestamps are untouched.
  • migrate() now accepts named files (migrationFiles) or plain SQL. It returns { applied, unknown }.
  • A database that has applied a migration this build doesn't know no longer throws db.future_schema. openDb logs a warning naming each such migration, and --preflight names them in its "preflight ok" line. Missing migrations are still applied. app.ts, main.ts --preflight and the chaos worker now pass migrationFiles.
  • A database from before the tracking table that is ahead of the build is still refused: it has only a count, so there is nothing to name.

Pins (src/core/migration-pins.json, scripts/pin-migrations.ts)

  • The pins file maps every migration's name to its text hash; all 117 current migrations are pinned.
  • The script adds pins for new migrations and never rewrites an existing one. The releases.json note asks the release agent to run it when cutting a release, so pulls never touch the file and can't collide in it.
  • test/schema-migrations.test.ts fails, naming the migration, when a pinned one is edited or deleted. A whitespace-only change doesn't count as an edit.

Tests changed and added (test/schema-migrations.test.ts)

  • I replaced "data ahead of this build is still refused", because #783 asks for that behaviour to change. It is now "data with one more migration than its code boots and names it", plus a kept refusal for data from before the tracking table.
  • New tests cover:
    • a copied database with one fewer migration than its code;
    • an unknown migration recorded without a name, which is named by its position and the start of its hash;
    • a fresh database recording every migration's name, in order;
    • a database from before names were kept getting them filled in with no other change;
    • pin breaks, and that pinning never rewrites a pin.
  • The either-order test now also checks that both migrations are recorded by name.

Not changed: a migration is still identified by its text hash, not its name. That's what lets moved or renumbered migrations be recognised, and existing databases need no rewrite. The rollback gate still compares migration counts.

Testing: the type check passes, and these test files pass: schema-migrations, schema-additive, the release-*, sentinel, chaos, db, preflight and health suites, and check-list (one test skipped). I didn't run the full check locally.

To try it: copy a forge database, add a migration file on one checkout, boot it, then boot a checkout without that file on the same data. It starts and logs database has migrations this build does not know with the file's name.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("db > future schema refuses to run") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs