Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
fix: exclude Go test files from migrations (pressly#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipoerner authored Mar 4, 2023
1 parent 0af59c1 commit b62288d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ func Down(tx *sql.Tx) error {
}
```

Note that Go migration files must begin with a numeric value, followed by an
underscore, and must not end with `*_test.go`.

# Development

This can be used to build local `goose` binaries without having the latest Go version installed locally.
Expand Down
5 changes: 5 additions & 0 deletions migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"runtime"
"sort"
"strings"
"time"
)

Expand Down Expand Up @@ -234,6 +235,10 @@ func collectMigrationsFS(fsys fs.FS, dirpath string, current, target int64) (Mig
continue // Skip any files that don't have version prefix.
}

if strings.HasSuffix(file, "_test.go") {
continue // Skip Go test files.
}

// Skip migrations already existing migrations registered via goose.AddMigration().
if _, ok := registeredGoMigrations[v]; ok {
continue
Expand Down

0 comments on commit b62288d

Please sign in to comment.