Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use filepath.Glob in bootstrap #416

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions cmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ package cmd

import (
"fmt"
"os"
"path/filepath"
"slices"

"github.com/spf13/cobra"
)
Expand All @@ -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)
}
}

Expand Down
Loading