Skip to content

Track applied migrations to skip column checks on startup#60

Open
andrew wants to merge 5 commits intomainfrom
track-migrations
Open

Track applied migrations to skip column checks on startup#60
andrew wants to merge 5 commits intomainfrom
track-migrations

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented Apr 4, 2026

Add a migrations table that records which schema migrations have been applied. MigrateSchema() now loads the set of applied migration names in one query and only runs new ones.

Three upgrade paths are handled:

  • Fresh database (Create): full schema includes the migrations table, all migrations recorded as applied
  • Old database without migrations table: table is created on first MigrateSchema call, each migration runs (idempotent) and gets recorded
  • Already migrated database: one SELECT from migrations, everything is skipped

Benchmarks for a fully migrated database (MigrateSchema as a no-op):

Metric Before After Change
sec/op 19.03µs 6.26µs -67%
B/op 2,126 1,352 -36%
allocs/op 66 43 -35%

Closes #54

andrew added 5 commits April 4, 2026 08:56
Add a migrations table that records which migrations have been applied.
On boot, load the set of applied names in one query and only run new ones.
A fully migrated database now does 1 query instead of ~12 HasColumn/HasTable
checks.

Fresh databases created via CreateSchema record all migrations as already
applied. Old databases get the migrations table on first MigrateSchema call
and each migration is recorded after it runs.

Closes #54
Skip HasTable/HasColumn checks when the migrations table already exists.
A fully migrated database now does one SELECT instead of ~12 individual
column and table checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Track applied migrations to skip column checks on startup

1 participant