package app import ( "fmt" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models" "gorm.io/driver/postgres" "gorm.io/gorm" ) type App struct { Db *gorm.DB Config *config.Config } func New() (*App, error) { cfg := config.New() dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", cfg.DBHost, cfg.DBPort, cfg.DBUser, cfg.DBPassword, cfg.DBName) db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) if err != nil { return nil, err } db.AutoMigrate(&models.Task{}, &models.GitRepoAltRepoTask{}, &models.RPMFile{}) db.FirstOrCreate(&models.ALTRepo{ Name: "Sisyphus", }) return &App{ Config: cfg, Db: db, }, nil }