32 lines
567 B
Go
32 lines
567 B
Go
|
package app
|
||
|
|
||
|
import (
|
||
|
"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/sqlite"
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
type App struct {
|
||
|
Db *gorm.DB
|
||
|
Config *config.Config
|
||
|
}
|
||
|
|
||
|
func New() (*App, error) {
|
||
|
db, err := gorm.Open(sqlite.Open("app.db"), &gorm.Config{})
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
db.AutoMigrate(&models.Task{}, &models.GitRepoAltRepoTask{})
|
||
|
|
||
|
db.FirstOrCreate(&models.ALTRepo{
|
||
|
Name: "Sisyphus",
|
||
|
})
|
||
|
|
||
|
return &App{
|
||
|
Config: config.New(),
|
||
|
Db: db,
|
||
|
}, nil
|
||
|
}
|