package main

import (
	"log"

	"github.com/joho/godotenv"

	"github.com/forgeo/forgebucket/internal/config"
	"github.com/forgeo/forgebucket/internal/db"
	"github.com/forgeo/forgebucket/internal/models/migrations"
)

func main() {
	_ = godotenv.Load()

	cfg, err := config.Load()
	if err != nil {
		log.Fatalf("config: %v", err)
	}

	engine, err := db.Open(cfg.DatabaseURL, cfg.Debug)
	if err != nil {
		log.Fatalf("db: %v", err)
	}
	defer engine.Close()

	log.Println("Running migrations...")
	if err := migrations.Run(engine); err != nil {
		log.Fatalf("migrate: %v", err)
	}
	log.Println("Migrations complete.")
}
