diff --git a/appview/database/migrations.go b/appview/database/migrations.go index 45b94e2..b2ec5a8 100644 --- a/appview/database/migrations.go +++ b/appview/database/migrations.go @@ -29,12 +29,14 @@ func dropStaleColumns(db *gorm.DB) { } for _, d := range drops { - if db.Migrator().HasColumn(d.table, d.column) { - if err := db.Exec(fmt.Sprintf(`ALTER TABLE %q DROP COLUMN %q`, d.table, d.column)).Error; err != nil { - slog.Warn("drop column failed", "table", d.table, "column", d.column, "err", err) - } else { - slog.Info("dropped stale column", "table", d.table, "column", d.column) - } + // Use raw SQL to check — GORM's HasColumn applies its own naming convention + // which defeats the purpose of checking for the misnamed column. + sql := fmt.Sprintf( + `ALTER TABLE %q DROP COLUMN IF EXISTS %q`, + d.table, d.column, + ) + if err := db.Exec(sql).Error; err != nil { + slog.Warn("drop column failed", "table", d.table, "column", d.column, "err", err) } } }