From 96f98b267e544666377c201d77ca0e96c38f968e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:45:48 +0000 Subject: [PATCH 1/3] Initial plan From c67f01b0056b5936cf917cf5d2842ff898156d37 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:53:07 +0000 Subject: [PATCH 2/3] feat(migrations): filter to only run numbered migrations, skip helper scripts Add regex pattern to only execute numbered migrations (e.g., 001_init.sql, 002_sample_data.sql) and skip helper scripts like bootstrap_existing_db.sql. This prevents the bootstrap script from being run automatically during the migration process, maintaining the intended "run once for existing DBs" bootstrap flow. Co-authored-by: techbuzzz <6938100+techbuzzz@users.noreply.github.com> --- cmd/server/main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/server/main.go b/cmd/server/main.go index 040930e..f1f0fcf 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -4,6 +4,7 @@ import ( "log" "net/http" "os" + "regexp" "strings" "github.com/gorilla/mux" @@ -283,12 +284,21 @@ func runMigrations(db *database.DB) error { rows.Close() // Apply pending migrations in order + // Only process numbered migrations (e.g., 001_init.sql, 002_sample_data.sql) + // Skip helper scripts like bootstrap_existing_db.sql + migrationPattern := regexp.MustCompile(`^\d{3}_.*\.sql$`) appliedCount := 0 for _, entry := range entries { if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".sql") { continue } + // Skip non-numbered migration files (e.g., bootstrap scripts) + if !migrationPattern.MatchString(entry.Name()) { + log.Printf("Skipping non-numbered migration file: %s", entry.Name()) + continue + } + // Skip if already applied if appliedMigrations[entry.Name()] { continue From 3fbea370e16219c0342fab616d521f415e0ed8c6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:54:19 +0000 Subject: [PATCH 3/3] refactor: move regex compilation outside loop for efficiency Move migration pattern compilation to the beginning of runMigrations function to avoid repeated compilation overhead on each function call. Co-authored-by: techbuzzz <6938100+techbuzzz@users.noreply.github.com> --- cmd/server/main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index f1f0fcf..2291ca1 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -249,6 +249,11 @@ func main() { func runMigrations(db *database.DB) error { log.Println("Running database migrations...") + // Compile regex pattern once for efficiency + // Only process numbered migrations (e.g., 001_init.sql, 002_sample_data.sql) + // Skip helper scripts like bootstrap_existing_db.sql + migrationPattern := regexp.MustCompile(`^\d{3}_.*\.sql$`) + // Create migrations tracking table if it doesn't exist createTableSQL := ` CREATE TABLE IF NOT EXISTS schema_migrations ( @@ -284,9 +289,6 @@ func runMigrations(db *database.DB) error { rows.Close() // Apply pending migrations in order - // Only process numbered migrations (e.g., 001_init.sql, 002_sample_data.sql) - // Skip helper scripts like bootstrap_existing_db.sql - migrationPattern := regexp.MustCompile(`^\d{3}_.*\.sql$`) appliedCount := 0 for _, entry := range entries { if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".sql") {