remove legacy migration conversion code
All checks were successful
Check / check (pull_request) Successful in 3m15s

Pre-1.0 software with no installed base — no need to handle
converting from old TEXT-based schema_migrations format.

Removed: convertLegacyMigrations, ensureBootstrapVersion,
readLegacyVersions, rebuildMigrationsTable, and
TestApplyMigrationsLegacyConversion.

Simplified bootstrapMigrationsTable to only check existence
and run 000_migration.sql if missing.
This commit is contained in:
user
2026-03-26 08:37:44 -07:00
parent 22cc1a7fb1
commit 6591f77dac
2 changed files with 2 additions and 213 deletions

View File

@@ -115,78 +115,3 @@ func TestApplyMigrationsIdempotent(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, 8, count)
}
func TestApplyMigrationsLegacyConversion(t *testing.T) {
t.Parallel()
db, err := sql.Open("sqlite3", ":memory:?_foreign_keys=on")
require.NoError(t, err)
defer func() { _ = db.Close() }()
ctx := context.Background()
// Simulate the old TEXT-based schema_migrations table.
_, err = db.ExecContext(ctx, `
CREATE TABLE schema_migrations (
version TEXT PRIMARY KEY,
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`)
require.NoError(t, err)
// Insert legacy filename-based versions (as if migrations 001-007 were applied).
legacyVersions := []string{
"001_initial.sql",
"002_remove_container_id.sql",
"003_add_ports.sql",
"004_add_commit_url.sql",
"005_add_webhook_secret_hash.sql",
"006_add_previous_image_id.sql",
"007_add_resource_limits.sql",
}
for _, v := range legacyVersions {
_, err = db.ExecContext(ctx,
"INSERT INTO schema_migrations (version) VALUES (?)", v)
require.NoError(t, err)
}
// Also create the application tables that would exist on a real database
// so that the migrations (001-007) don't fail when re-applied.
// Actually, since the legacy versions will be converted and recognized
// as already-applied, the DDL migrations won't re-run. We just need
// to make sure ApplyMigrations succeeds.
// Run ApplyMigrations — this should convert legacy versions and
// skip all already-applied migrations.
err = database.ApplyMigrations(ctx, db, nil)
require.NoError(t, err)
// Verify version 0 is now present (from bootstrap).
var zeroVersion int
err = db.QueryRowContext(ctx,
"SELECT version FROM schema_migrations WHERE version = 0",
).Scan(&zeroVersion)
require.NoError(t, err)
assert.Equal(t, 0, zeroVersion)
// Verify all 8 versions are present (0 through 7).
var count int
err = db.QueryRowContext(ctx,
"SELECT COUNT(*) FROM schema_migrations",
).Scan(&count)
require.NoError(t, err)
assert.Equal(t, 8, count)
// Verify versions are stored as integers, not text filenames.
var maxVersion int
err = db.QueryRowContext(ctx,
"SELECT MAX(version) FROM schema_migrations",
).Scan(&maxVersion)
require.NoError(t, err)
assert.Equal(t, 7, maxVersion)
}