This commit is contained in:
2025-08-23 22:31:47 -04:00
parent 9ca9c53baf
commit e5bccc85c2
22 changed files with 2405 additions and 209 deletions

View File

@ -38,6 +38,9 @@ func main() {
)
// Initialize database
logger.Info("Connecting to database",
zap.String("dsn", cfg.GetDatabaseDSNForLogging()))
db, err := database.NewPostgresProvider(
cfg.GetDatabaseDSN(),
cfg.GetInt("DB_MAX_OPEN_CONNS"),
@ -45,14 +48,15 @@ func main() {
cfg.GetString("DB_CONN_MAX_LIFETIME"),
)
if err != nil {
logger.Fatal("Failed to initialize database", zap.Error(err))
logger.Fatal("Failed to initialize database",
zap.String("dsn", cfg.GetDatabaseDSNForLogging()),
zap.Error(err))
}
logger.Info("Database connection established successfully")
// Run database migrations
logger.Info("Running database migrations")
if err := db.Migrate(context.Background(), cfg.GetString("MIGRATION_PATH")); err != nil {
logger.Fatal("Failed to run migrations", zap.Error(err))
}
// Database migrations are handled by PostgreSQL docker-entrypoint-initdb.d
logger.Info("Database migrations are handled by PostgreSQL on container startup")
// Initialize repositories
appRepo := postgres.NewApplicationRepository(db)
@ -69,7 +73,7 @@ func main() {
healthHandler := handlers.NewHealthHandler(db, logger)
appHandler := handlers.NewApplicationHandler(appService, authService, logger)
tokenHandler := handlers.NewTokenHandler(tokenService, authService, logger)
authHandler := handlers.NewAuthHandler(authService, tokenService, logger)
authHandler := handlers.NewAuthHandler(authService, tokenService, cfg, logger)
// Set up router
router := setupRouter(cfg, logger, healthHandler, appHandler, tokenHandler, authHandler)