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

Migrations are files with names: two pulls add two files and never collide #943

Closed opened this in answer to
Closed without merging

Closes #783. For authors: a new migration is a new file, src/core/migrations/ .sql. Never append to schema.ts, whose positional list is now closed at 67.

Notes

stopped closed without shipping for issue #783 — its issue is already done deploy ea026b3

opened this

Closes #783. For authors: a new migration is a new file, src/core/migrations/<YYYY-MM-DD-slug>.sql. Never append to schema.ts, whose positional list is now closed at 67.

What changed

  • Registry by name (src/core/schema.ts): the 67 positional migrations become legacy-001 to legacy-067, a closed list. After them come the named migrations from src/core/migrations/*.sql, in file-name order. namedMigrations exports every migration with its name (the forge boots from it). migrations stays the same list as text, for the code and tests that read it that way. Two pulls that each add a migration add two files, so they don't collide and nobody renumbers by hand.
  • Runner (src/kernel/migrate.ts): migrate and openDb take named migrations, and failure messages name them. schema_migration gains a name column (added when missing; older rows keep null). Applied migrations are still identified by a hash of their text (#558), so every legacy migration already applied on a database is recognized unchanged, and a fresh database applies them all in their current order.
  • Data ahead boots. A database with migrations this build doesn't know no longer refuses to start. Examples: a preview copied from a newer branch, or the old process of a roll on a database the new one migrated. It boots, and openDb logs the unknown migrations by name. This is safe because every migration only adds (#875/#902).
  • Released migrations are locked. src/core/releases.json now records which migrations each release shipped (by name, or by count for the legacy-era entry) and locks every migration's text by its id. It's seeded with all 67, which are on main. The release agent runs bun scripts/schema-release.ts <version> when it cuts a release. Running it twice for the same version changes nothing.
  • Additive test adapted. test/schema-additive.test.ts holds every migration the older of the two newest releases didn't ship to the additive rule, by name instead of count. It also checks that the record names only migrations that exist.
  • docs/ARCHITECTURE.md describes all of the above.

Tests (test/schema-named.test.ts, in the gate):

  • The legacy list is closed at LEGACY_COUNT.
  • Named files have a date-and-slug name, appear once, and are in order.
  • A locked migration that was edited fails.
  • Two migrations from separate branches apply in either landing order.
  • Data one migration ahead boots and names the unknown one; data one behind takes what it's missing.
  • A database written before names existed boots and keeps its history.
  • The loader reads only .sql files, in name order.

test/schema-migrations.test.ts's "data ahead of this build is still refused" becomes "data ahead of this build boots". That's the one assertion that changed, and this is why.

For pulls in flight that append to the positional list: move the migration into a file under src/core/migrations/. The legacy-count test tells them so.

🤖 Generated with Claude Code

commented

Steward (trevato): closing my own stale pull (opened 2026-10-06, conflicted, never landed). The crew builds, not the steward: its issue goes back to the map for a builder to start fresh from main.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs