From 515dd543792fe1f785869ec1d883a4aa57a1502d Mon Sep 17 00:00:00 2001 From: Ryan Slade Date: Fri, 18 Oct 2024 13:39:50 +0200 Subject: [PATCH] Use filepath.Glob in bootstrap (#416) It does most of the work for us. --- cmd/bootstrap.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/cmd/bootstrap.go b/cmd/bootstrap.go index 8666190a..fc95a350 100644 --- a/cmd/bootstrap.go +++ b/cmd/bootstrap.go @@ -4,9 +4,7 @@ package cmd import ( "fmt" - "os" "path/filepath" - "slices" "github.com/spf13/cobra" ) @@ -27,22 +25,14 @@ in lexicographical order. All migrations are completed.`, defer m.Close() // open folder and read all json files - files, err := os.ReadDir(migrationsDir) + files, err := filepath.Glob(filepath.Join(migrationsDir, "*.json")) if err != nil { return fmt.Errorf("reading migration directory: %w", err) } - migrationFiles := []string{} - for _, file := range files { - if file.IsDir() || filepath.Ext(file.Name()) != ".json" { - continue - } - migrationFiles = append(migrationFiles, filepath.Join(migrationsDir, file.Name())) - } - slices.Sort(migrationFiles) - for _, fileName := range migrationFiles { - if err := runMigrationFromFile(cmd.Context(), m, fileName, true); err != nil { - return fmt.Errorf("running migration file '%s': %w", fileName, err) + for _, file := range files { + if err := runMigrationFromFile(cmd.Context(), m, file, true); err != nil { + return fmt.Errorf("running migration file %q: %w", file, err) } }