Auto-apply migrations on startup

This commit is contained in:
2026-02-05 23:30:33 +03:00
parent ad59128f0e
commit 686c310466
2 changed files with 117 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ import (
"reanimator/internal/api"
"reanimator/internal/config"
"reanimator/internal/repository"
"reanimator/internal/repository/migrate"
)
func main() {
@@ -28,6 +29,10 @@ func main() {
defer func() {
_ = db.Close()
}()
if err := migrate.EnsureSchema(db, cfg.MigrationsDir); err != nil {
log.Fatalf("apply migrations: %v", err)
}
log.Printf("database schema ready")
srv := api.NewServer(cfg.HTTPAddr, cfg.ReadTimeout, cfg.WriteTimeout, db)