Skip to content

Commit

Permalink
fix: use context.Background to get context
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofnds committed Dec 27, 2023
1 parent 96c8cfe commit 9f8b518
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cmd/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ func main() {
os.Exit(1)
}

ctx := context.Background()

app := fx.New(
logger.NopLoggerProvider,
config.Module,
postgres.Module,
fx.Invoke(func(ctx context.Context, db *sql.DB, config postgres.Config) error {
fx.Invoke(func(db *sql.DB, config postgres.Config) error {
goose.SetBaseFS(migrations)
action, args := os.Args[1], os.Args[2:]
err := goose.RunContext(ctx, action, db, dir(action), args...)
Expand All @@ -45,8 +47,9 @@ func main() {
return err
}),
)
defer func() { _ = app.Stop(context.Background()) }()
_ = app.Start(context.Background())

defer func() { checkErr(app.Stop(ctx)) }()
checkErr(app.Start(ctx))
}

func dir(action string) string {
Expand All @@ -56,3 +59,9 @@ func dir(action string) string {

return "migrations"
}

func checkErr(err error) {
if err != nil {
panic(err)
}
}

0 comments on commit 9f8b518

Please sign in to comment.