Remove backwards compat code: no installed base pre-1.0

- Simplify bootstrapMigrationsTable to just check table existence and
  apply 000.sql if missing — no legacy DB detection
- Remove ensureBootstrapVersionRecorded (legacy backfill path)
- Remove applyBootstrapMigration (separate helper, now inlined)
- Remove TestBootstrapMigrationsTable_ExistingTableBackwardsCompat
- Simplify 000.sql header comment
This commit is contained in:
clawbot
2026-03-17 19:47:59 -07:00
committed by clawbot
parent 48926747a0
commit 2cabd48a8a
3 changed files with 2 additions and 103 deletions

View File

@@ -148,9 +148,7 @@ func collectMigrations() ([]string, error) {
}
// bootstrapMigrationsTable ensures the schema_migrations table exists
// by applying 000.sql directly. For databases that already have the
// table (created by older code), it records version "000" for
// consistency.
// by applying 000.sql if the table is missing.
func bootstrapMigrationsTable(ctx context.Context, db *sql.DB, log *slog.Logger) error {
var tableExists int
@@ -162,47 +160,9 @@ func bootstrapMigrationsTable(ctx context.Context, db *sql.DB, log *slog.Logger)
}
if tableExists > 0 {
return ensureBootstrapVersionRecorded(ctx, db, log)
}
return applyBootstrapMigration(ctx, db, log)
}
// ensureBootstrapVersionRecorded checks whether version "000" is already
// recorded in an existing schema_migrations table and inserts it if not.
func ensureBootstrapVersionRecorded(ctx context.Context, db *sql.DB, log *slog.Logger) error {
var recorded int
err := db.QueryRowContext(ctx,
"SELECT COUNT(*) FROM schema_migrations WHERE version = ?",
bootstrapVersion,
).Scan(&recorded)
if err != nil {
return fmt.Errorf("failed to check bootstrap migration status: %w", err)
}
if recorded > 0 {
return nil
}
_, err = db.ExecContext(ctx,
"INSERT INTO schema_migrations (version) VALUES (?)",
bootstrapVersion,
)
if err != nil {
return fmt.Errorf("failed to record bootstrap migration: %w", err)
}
if log != nil {
log.Info("recorded bootstrap migration for existing table", "version", bootstrapVersion)
}
return nil
}
// applyBootstrapMigration reads and executes 000.sql to create the
// schema_migrations table on a fresh database.
func applyBootstrapMigration(ctx context.Context, db *sql.DB, log *slog.Logger) error {
content, err := schemaFS.ReadFile("schema/000.sql")
if err != nil {
return fmt.Errorf("failed to read bootstrap migration 000.sql: %w", err)
@@ -225,10 +185,6 @@ func applyBootstrapMigration(ctx context.Context, db *sql.DB, log *slog.Logger)
return fmt.Errorf("failed to record bootstrap migration: %w", err)
}
if log != nil {
log.Info("bootstrap migration applied successfully", "version", bootstrapVersion)
}
return nil
}