Skip to content

Commit 7762ba4

Browse files
starbopsclaude
andcommitted
debug(migration): add enhanced debugging to identify CI migration failures
Add comprehensive debugging to migration command to identify why migration 005 is not being applied in CI environment while working correctly locally. ## Changes Made ### Enhanced Migration File Detection - Added listAvailableMigrations() function to show what files golang-migrate detects - Lists both up and down migration files found in migrations directory - Shows exact count and filenames that will be processed ### Debugging Output - Shows migration files found before applying migrations - Helps identify if migration file detection is the issue in CI - Maintains existing validation and state checking This will help pinpoint whether the issue is: - Migration files not being found/read in CI - File permissions or path issues - golang-migrate library differences between environments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 510de72 commit 7762ba4

1 file changed

Lines changed: 43 additions & 8 deletions

File tree

cmd/migrate/main.go

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"strings"
89

10+
_ "github.com/jackc/pgx/v5/stdlib"
911
"github.com/voidrunnerhq/voidrunner/internal/config"
1012
"github.com/voidrunnerhq/voidrunner/internal/database"
1113
"github.com/voidrunnerhq/voidrunner/pkg/logger"
12-
_ "github.com/jackc/pgx/v5/stdlib"
1314
)
1415

1516
func main() {
@@ -52,32 +53,37 @@ func main() {
5253
case "up":
5354
// Enhanced debugging for migration up
5455
fmt.Println("=== Database Migration Debug Info ===")
55-
fmt.Printf("Database: %s@%s:%s/%s (ssl=%s)\n",
56-
cfg.Database.User, cfg.Database.Host, cfg.Database.Port,
56+
fmt.Printf("Database: %s@%s:%s/%s (ssl=%s)\n",
57+
cfg.Database.User, cfg.Database.Host, cfg.Database.Port,
5758
cfg.Database.Database, cfg.Database.SSLMode)
5859
fmt.Printf("Migrations path: %s\n", migrationsPath)
59-
60+
61+
// Debug: List migration files that golang-migrate can see
62+
if err := listAvailableMigrations(migrationsPath); err != nil {
63+
log.Warn("Failed to list migration files", "error", err)
64+
}
65+
6066
// Check current migration state before applying
6167
if err := debugMigrationState(migrateConfig); err != nil {
6268
log.Warn("Failed to get migration state before applying", "error", err)
6369
}
64-
70+
6571
if err := database.MigrateUp(migrateConfig); err != nil {
6672
fmt.Fprintf(os.Stderr, "Migration failed: %v\n", err)
6773
os.Exit(1)
6874
}
69-
75+
7076
// Check migration state after applying
7177
if err := debugMigrationState(migrateConfig); err != nil {
7278
log.Warn("Failed to get migration state after applying", "error", err)
7379
}
74-
80+
7581
// Validate critical database objects exist
7682
if err := validateDatabaseObjects(migrateConfig); err != nil {
7783
fmt.Fprintf(os.Stderr, "Database object validation failed: %v\n", err)
7884
os.Exit(1)
7985
}
80-
86+
8187
fmt.Println("Migrations applied successfully")
8288

8389
case "down":
@@ -196,3 +202,32 @@ func validateDatabaseObjects(cfg *database.MigrateConfig) error {
196202
fmt.Println("Database object validation passed")
197203
return nil
198204
}
205+
206+
// listAvailableMigrations shows what migration files are available to golang-migrate
207+
func listAvailableMigrations(migrationsPath string) error {
208+
fmt.Println("=== Available Migration Files ===")
209+
210+
// Convert file:// path to regular path for directory listing
211+
path := strings.TrimPrefix(migrationsPath, "file://")
212+
213+
files, err := os.ReadDir(path)
214+
if err != nil {
215+
return fmt.Errorf("failed to read migrations directory: %w", err)
216+
}
217+
218+
upFiles := []string{}
219+
downFiles := []string{}
220+
221+
for _, file := range files {
222+
if strings.HasSuffix(file.Name(), ".up.sql") {
223+
upFiles = append(upFiles, file.Name())
224+
} else if strings.HasSuffix(file.Name(), ".down.sql") {
225+
downFiles = append(downFiles, file.Name())
226+
}
227+
}
228+
229+
fmt.Printf("Found %d up migrations: %v\n", len(upFiles), upFiles)
230+
fmt.Printf("Found %d down migrations: %v\n", len(downFiles), downFiles)
231+
232+
return nil
233+
}

0 commit comments

Comments
 (0)