move out db migtration to separate function
This commit is contained in:
parent
17e63b59fa
commit
ccc98b4298
@ -47,19 +47,32 @@ type BotController struct {
|
|||||||
updates tgbotapi.UpdatesChannel
|
updates tgbotapi.UpdatesChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DBMigrate() (*gorm.DB, error) {
|
||||||
|
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
|
||||||
|
if err != nil {
|
||||||
|
return db, err
|
||||||
|
}
|
||||||
|
|
||||||
|
db.AutoMigrate(&User{})
|
||||||
|
db.AutoMigrate(&BotContent{})
|
||||||
|
|
||||||
|
return db, err
|
||||||
|
}
|
||||||
|
|
||||||
func GetBotController() BotController {
|
func GetBotController() BotController {
|
||||||
cfg := config.GetConfig()
|
cfg := config.GetConfig()
|
||||||
fmt.Printf("Token value: '%v'\n", cfg.BotToken)
|
fmt.Printf("Token value: '%v'\n", cfg.BotToken)
|
||||||
fmt.Printf("Admin password: '%v'\n", cfg.AdminPass)
|
fmt.Printf("Admin password: '%v'\n", cfg.AdminPass)
|
||||||
|
|
||||||
bot, err := tgbotapi.NewBotAPI(cfg.BotToken)
|
bot, err := tgbotapi.NewBotAPI(cfg.BotToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
|
db, err := DBMigrate()
|
||||||
db.AutoMigrate(&User{})
|
if err != nil {
|
||||||
db.AutoMigrate(&BotContent{})
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
bot.Debug = true
|
bot.Debug = true
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user