Scope

A single commit on 2026-04-27. Late but significant — added the schema_migrations tracking table that should have existed from the start.

Commit

81c2568 — 2026-04-27 — feat(migrations): add schema_migrations tracking and resolve 007 issues

Co-author: Claude Opus 4.7 (1M context).

What landed:

  • migrations/000_schema_migrations.sql — bootstraps a tracking table:
    • version PRIMARY KEY (TEXT).
    • name nullable TEXT for legacy compatibility (some migrations insert without supplying a name).
    • applied_at TIMESTAMPTZ DEFAULT NOW().
  • Renamed later-committed 007_add_archive_tables.sql009_add_archive_tables.sql to resolve a numbering collision with 007_pgvector_company_embeddings.sql (kept as 007).
  • New runner: scripts/migrate.ts. Idempotent. Uses Bun.sql for bookkeeping and psql -f for migration bodies. Supports --mark-applied <version> to backfill rows for migrations applied out-of-band before tracking existed.
  • Fixed migration 007 (the surviving 007, pgvector): removed an illegal BEGIN/COMMIT wrapper around CREATE INDEX CONCURRENTLY statements. Dropped a stray idx_bv_sni_primary that referenced a column that does not exist on bolagsverket_companies.
  • Wired bun run migrate in package.json.

Verification cited in body: “all 10 migrations apply cleanly against the live DB and a re-run is a no-op (applied=0 skipped=10).”

Significance

  • Before this commit the project had 10 migrations and no record of which ones had been applied. Anyone setting up a fresh DB had to read each *.sql and check by hand.
  • The numbering collision is a permanent record: if you git log for 007_add_archive_tables.sql you will find it under both filenames. This commit is where the rename happened.
  • The --mark-applied mode is the migration path for existing prod databases. Run it once per applied version to backfill the tracking table.

See also

Schema Migrations, Database Schema, History Archive Era, History Overview.

See also