Move schema_migrations table creation from Go code into 000.sql
All checks were successful
check / check (push) Successful in 1m43s
All checks were successful
check / check (push) Successful in 1m43s
The schema_migrations table definition now lives in internal/database/schema/000.sql instead of being hardcoded as an inline SQL string in database.go. A bootstrap step checks sqlite_master for the table and applies 000.sql when it is missing. Existing databases that already have the table (created by older inline code) get version 000 back-filled so the normal migration loop skips the file. Also deduplicates the migration logic: both the Database.runMigrations method and the exported ApplyMigrations helper now delegate to a single applyMigrations function. Adds database_test.go with tests for fresh migration, idempotency, bootstrap on a fresh DB, and backwards compatibility with legacy DBs.
This commit is contained in:
9
internal/database/schema/000.sql
Normal file
9
internal/database/schema/000.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- Migration 000: Schema migrations tracking table
|
||||
-- This must be the first migration applied. The bootstrap logic in
|
||||
-- database.go applies it directly (bypassing the normal migration
|
||||
-- loop) when the schema_migrations table does not yet exist.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||
version TEXT PRIMARY KEY,
|
||||
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
Reference in New Issue
Block a user