Change schema_migrations version from TEXT to INTEGER
All checks were successful
check / check (push) Successful in 1m42s

This commit is contained in:
clawbot
2026-03-19 23:07:03 -07:00
parent 2074571a87
commit 49398c1f0f
3 changed files with 41 additions and 35 deletions

View File

@@ -26,33 +26,33 @@ func TestParseMigrationVersion(t *testing.T) {
tests := []struct {
name string
filename string
want string
want int
wantErr bool
}{
{
name: "version only",
filename: "001.sql",
want: "001",
want: 1,
},
{
name: "version with description",
filename: "001_initial_schema.sql",
want: "001",
want: 1,
},
{
name: "multi-digit version",
filename: "042_add_indexes.sql",
want: "042",
want: 42,
},
{
name: "long version number",
filename: "00001_long_prefix.sql",
want: "00001",
want: 1,
},
{
name: "description with multiple underscores",
filename: "003_add_user_auth_tables.sql",
want: "003",
want: 3,
},
{
name: "empty filename",
@@ -81,7 +81,7 @@ func TestParseMigrationVersion(t *testing.T) {
got, err := ParseMigrationVersion(tt.filename)
if tt.wantErr {
if err == nil {
t.Errorf("ParseMigrationVersion(%q) expected error, got %q", tt.filename, got)
t.Errorf("ParseMigrationVersion(%q) expected error, got %d", tt.filename, got)
}
return
@@ -94,7 +94,7 @@ func TestParseMigrationVersion(t *testing.T) {
}
if got != tt.want {
t.Errorf("ParseMigrationVersion(%q) = %q, want %q", tt.filename, got, tt.want)
t.Errorf("ParseMigrationVersion(%q) = %d, want %d", tt.filename, got, tt.want)
}
})
}
@@ -109,16 +109,16 @@ func TestApplyMigrations_CreatesSchemaAndTables(t *testing.T) {
}
// The schema_migrations table must exist and contain at least
// version "000" (the bootstrap) and "001" (the initial schema).
// version 0 (the bootstrap) and 1 (the initial schema).
rows, err := db.Query("SELECT version FROM schema_migrations ORDER BY version")
if err != nil {
t.Fatalf("failed to query schema_migrations: %v", err)
}
defer rows.Close()
var versions []string
var versions []int
for rows.Next() {
var v string
var v int
if err := rows.Scan(&v); err != nil {
t.Fatalf("failed to scan version: %v", err)
}
@@ -134,12 +134,12 @@ func TestApplyMigrations_CreatesSchemaAndTables(t *testing.T) {
t.Fatalf("expected at least 2 migrations recorded, got %d: %v", len(versions), versions)
}
if versions[0] != "000" {
t.Errorf("first recorded migration = %q, want %q", versions[0], "000")
if versions[0] != 0 {
t.Errorf("first recorded migration = %d, want %d", versions[0], 0)
}
if versions[1] != "001" {
t.Errorf("second recorded migration = %q, want %q", versions[1], "001")
if versions[1] != 1 {
t.Errorf("second recorded migration = %d, want %d", versions[1], 1)
}
// Verify that the application tables created by 001.sql exist.
@@ -176,13 +176,13 @@ func TestApplyMigrations_Idempotent(t *testing.T) {
// Verify no duplicate rows in schema_migrations.
var count int
err := db.QueryRow("SELECT COUNT(*) FROM schema_migrations WHERE version = '000'").Scan(&count)
err := db.QueryRow("SELECT COUNT(*) FROM schema_migrations WHERE version = 0").Scan(&count)
if err != nil {
t.Fatalf("failed to count 000 rows: %v", err)
t.Fatalf("failed to count version 0 rows: %v", err)
}
if count != 1 {
t.Errorf("expected exactly 1 row for version 000, got %d", count)
t.Errorf("expected exactly 1 row for version 0, got %d", count)
}
}
@@ -208,17 +208,17 @@ func TestBootstrapMigrationsTable_FreshDatabase(t *testing.T) {
t.Fatalf("schema_migrations table not created")
}
// Version "000" must be recorded.
// Version 0 must be recorded.
var recorded int
err = db.QueryRow(
"SELECT COUNT(*) FROM schema_migrations WHERE version = '000'",
"SELECT COUNT(*) FROM schema_migrations WHERE version = 0",
).Scan(&recorded)
if err != nil {
t.Fatalf("failed to check version: %v", err)
}
if recorded != 1 {
t.Errorf("expected version 000 to be recorded, got count %d", recorded)
t.Errorf("expected version 0 to be recorded, got count %d", recorded)
}
}