fix: migration runner only executes .up.sql files, skips .down.sql and seeds

The migration runner was collecting all .sql files alphabetically, which
caused .down.sql rollback files (DROP TABLE) to execute before .up.sql
files on restart with a persisted postgres volume. Filter to only .up.sql
files — these are idempotent (IF NOT EXISTS) and safe to re-run.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shankar0123
2026-03-24 12:08:12 -04:00
parent 4049dc8c7f
commit 8054719956
+2 -2
View File
@@ -42,10 +42,10 @@ func RunMigrations(db *sql.DB, migrationsPath string) error {
return fmt.Errorf("failed to read migrations directory: %w", err)
}
// Sort and filter SQL files
// Sort and filter to only .up.sql migration files (skip .down.sql rollbacks and seed files)
var sqlFiles []string
for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), ".sql") {
if !file.IsDir() && strings.HasSuffix(file.Name(), ".up.sql") {
sqlFiles = append(sqlFiles, file.Name())
}
}