fix: default migration authoring directory to cwd

This commit is contained in:
end committed 2026-10-28 15:39:47 -07:00
1 parent 501629f225
commit b49a6ae449
2 files changed
+31 -6

No files matched your search

+3 -3
View File
@@ -21,16 +21,16 @@ func command() *urfavecli.Command {
root := &urfavecli.Command{Name: "corestack-goose", Usage: "Author migrations before deployment"} root := &urfavecli.Command{Name: "corestack-goose", Usage: "Author migrations before deployment"}
for _, name := range []string{"create", "fix"} { for _, name := range []string{"create", "fix"} {
root.Commands = append(root.Commands, &urfavecli.Command{Name: name, root.Commands = append(root.Commands, &urfavecli.Command{Name: name,
Flags: []urfavecli.Flag{&urfavecli.StringFlag{Name: "dir", Required: true}}, Flags: []urfavecli.Flag{&urfavecli.StringFlag{Name: "dir", Value: ".", Usage: "Migration directory (defaults to the current working directory)"}},
Action: func(_ context.Context, cmd *urfavecli.Command) error { Action: func(_ context.Context, cmd *urfavecli.Command) error {
if name == "create" { if name == "create" {
if cmd.NArg() != 2 { if cmd.NArg() != 2 {
return fmt.Errorf("usage: create --dir <dir> <name> sql|go") return fmt.Errorf("usage: create [--dir <dir>] <name> sql|go")
} }
return authoring.Create(cmd.String("dir"), cmd.Args().Get(0), cmd.Args().Get(1)) return authoring.Create(cmd.String("dir"), cmd.Args().Get(0), cmd.Args().Get(1))
} }
if cmd.NArg() != 0 { if cmd.NArg() != 0 {
return fmt.Errorf("usage: fix --dir <dir>") return fmt.Errorf("usage: fix [--dir <dir>]")
} }
return authoring.Fix(cmd.String("dir")) return authoring.Fix(cmd.String("dir"))
}, },
+28 -3
View File
@@ -41,11 +41,36 @@ func TestGeneratedConsumerAndArtifactBoundary(t *testing.T) {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
osName = "linux" osName = "linux"
} }
for _, tc := range []struct{ name, kind string }{{"initial", "sql"}, {"test", "go"}, {"create_test", "go"}, {osName, "go"}} { for i, tc := range []struct{ name, kind string }{{"initial", "sql"}, {"test", "go"}, {"create_test", "go"}, {osName, "go"}} {
execute(dir, tool, "create", "--dir", migrations, tc.name, tc.kind) if i%2 == 0 {
execute(dir, tool, "fix", "--dir", migrations) execute(migrations, tool, "create", tc.name, tc.kind)
execute(migrations, tool, "fix")
} else {
execute(dir, tool, "create", "--dir", migrations, tc.name, tc.kind)
execute(dir, tool, "fix", "--dir", migrations)
}
} }
execute(dir, tool, "fix", "--dir", migrations) execute(dir, tool, "fix", "--dir", migrations)
entries, err := os.ReadDir(migrations)
if err != nil {
t.Fatal(err)
}
wantFiles := []string{"00001_initial.sql", "00002_test_migration.go", "00003_create_test_migration.go", "00004_" + osName + "_migration.go", "register.go"}
if len(entries) != len(wantFiles) {
t.Fatalf("migration files: %v", entries)
}
for i, entry := range entries {
if entry.Name() != wantFiles[i] {
t.Fatalf("migration file: got %s, want %s", entry.Name(), wantFiles[i])
}
}
entries, err = os.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
if len(entries) != 2 || entries[0].Name() != "corestack-goose" || entries[1].Name() != "migrations" {
t.Fatalf("unexpected writes outside migration directory: %v", entries)
}
source, err := os.ReadFile("testdata/consumer/main.go") source, err := os.ReadFile("testdata/consumer/main.go")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)