Skip to content

Commit 515dd54

Browse files
authored
Use filepath.Glob in bootstrap (#416)
It does most of the work for us.
1 parent f628060 commit 515dd54

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

cmd/bootstrap.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ package cmd
44

55
import (
66
"fmt"
7-
"os"
87
"path/filepath"
9-
"slices"
108

119
"github.com/spf13/cobra"
1210
)
@@ -27,22 +25,14 @@ in lexicographical order. All migrations are completed.`,
2725
defer m.Close()
2826

2927
// open folder and read all json files
30-
files, err := os.ReadDir(migrationsDir)
28+
files, err := filepath.Glob(filepath.Join(migrationsDir, "*.json"))
3129
if err != nil {
3230
return fmt.Errorf("reading migration directory: %w", err)
3331
}
34-
migrationFiles := []string{}
35-
for _, file := range files {
36-
if file.IsDir() || filepath.Ext(file.Name()) != ".json" {
37-
continue
38-
}
39-
migrationFiles = append(migrationFiles, filepath.Join(migrationsDir, file.Name()))
40-
}
41-
slices.Sort(migrationFiles)
4232

43-
for _, fileName := range migrationFiles {
44-
if err := runMigrationFromFile(cmd.Context(), m, fileName, true); err != nil {
45-
return fmt.Errorf("running migration file '%s': %w", fileName, err)
33+
for _, file := range files {
34+
if err := runMigrationFromFile(cmd.Context(), m, file, true); err != nil {
35+
return fmt.Errorf("running migration file %q: %w", file, err)
4636
}
4737
}
4838

0 commit comments

Comments
 (0)