M1/#291: run migrations + open pool on startup

This commit is contained in:
2026-04-19 01:12:23 +00:00
parent 9c66736916
commit e54482409a
+14 -3
View File
@@ -12,6 +12,7 @@ import (
"time"
"git.fabledsword.com/bvandeusen/minstrel/internal/config"
"git.fabledsword.com/bvandeusen/minstrel/internal/db"
"git.fabledsword.com/bvandeusen/minstrel/internal/logging"
"git.fabledsword.com/bvandeusen/minstrel/internal/server"
)
@@ -43,6 +44,19 @@ func run() error {
"log_format", cfg.Log.Format,
)
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
if err := db.Migrate(cfg.Database.URL, logger); err != nil {
return fmt.Errorf("migrate: %w", err)
}
pool, err := db.Open(ctx, cfg.Database.URL)
if err != nil {
return fmt.Errorf("open db: %w", err)
}
defer pool.Close()
srv := server.New(logger)
httpServer := &http.Server{
Addr: cfg.Server.Address,
@@ -50,9 +64,6 @@ func run() error {
ReadHeaderTimeout: 10 * time.Second,
}
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
errCh := make(chan error, 1)
go func() {
logger.Info("listening", "address", cfg.Server.Address)