Maxim Slipenko
733cebfd81
Reviewed-on: https://code.alt-gnome.ru/aides-infra/aides-repo-api/pulls/7 Co-authored-by: Maxim Slipenko <no-reply@maxim.slipenko.com> Co-committed-by: Maxim Slipenko <no-reply@maxim.slipenko.com>
36 lines
756 B
Go
36 lines
756 B
Go
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
|
|
}
|