fix: database is closed
Deploy / Test, build and deploy (push) Failing after 2m13s

This commit is contained in:
2026-06-08 15:42:08 +00:00
parent e074eeedf2
commit d30dd3f90f
+16 -5
View File
@@ -96,6 +96,11 @@ func Run(ctx context.Context, opts Options) error {
return errors.New("-halt requires DB_DSN")
}
if cfg.DB.MigrationsAutoApply {
if err := applyMigrations(ctx, cfg); err != nil {
return err
}
}
db, err := openDB(ctx, cfg)
if err != nil {
return err
@@ -103,11 +108,6 @@ func Run(ctx context.Context, opts Options) error {
defer func() {
_ = db.Close()
}()
if cfg.DB.MigrationsAutoApply {
if err := mysqlrepo.ApplyMigrations(ctx, db.DB); err != nil {
return err
}
}
repo := mysqlrepo.NewRepository(db)
if opts.Halt {
if strings.TrimSpace(opts.Reason) == "" {
@@ -351,6 +351,17 @@ func minPositive(a, b int) int {
}
}
func applyMigrations(ctx context.Context, cfg config.Config) error {
db, err := openDB(ctx, cfg)
if err != nil {
return err
}
defer func() {
_ = db.Close()
}()
return mysqlrepo.ApplyMigrations(ctx, db.DB)
}
func openDB(ctx context.Context, cfg config.Config) (*sqlx.DB, error) {
db, err := sqlx.Open("mysql", cfg.DB.DSN)
if err != nil {