From 8054719956b1ae3b46346ba1262335e982ab87ea Mon Sep 17 00:00:00 2001 From: shankar0123 Date: Tue, 24 Mar 2026 12:08:12 -0400 Subject: [PATCH] fix: migration runner only executes .up.sql files, skips .down.sql and seeds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- internal/repository/postgres/db.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/repository/postgres/db.go b/internal/repository/postgres/db.go index 549d62c..be16e6d 100644 --- a/internal/repository/postgres/db.go +++ b/internal/repository/postgres/db.go @@ -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()) } }