add config
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"rockhu-bot/local/model"
|
||||
"time"
|
||||
@@ -11,8 +12,9 @@ import (
|
||||
)
|
||||
|
||||
func Start(di *dig.Container) {
|
||||
dbConn := os.Getenv("DB_CONNECTION")
|
||||
db, err := gorm.Open(postgres.New(postgres.Config{
|
||||
DSN: os.Getenv("CONNECTION_STRINGS"),
|
||||
DSN: dbConn,
|
||||
PreferSimpleProtocol: true,
|
||||
}), &gorm.Config{
|
||||
NowFunc: func() time.Time {
|
||||
@@ -20,13 +22,13 @@ func Start(di *dig.Container) {
|
||||
return time.Now().In(utc)
|
||||
}})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
log.Panic("failed to connect database")
|
||||
}
|
||||
err = di.Provide(func() *gorm.DB {
|
||||
return db
|
||||
})
|
||||
if err != nil {
|
||||
panic("failed to bind database")
|
||||
log.Panic("failed to bind database")
|
||||
}
|
||||
Migrate(db)
|
||||
}
|
||||
@@ -34,6 +36,6 @@ func Start(di *dig.Container) {
|
||||
func Migrate(db *gorm.DB) {
|
||||
err := db.AutoMigrate(&model.ConcertModel{})
|
||||
if err != nil {
|
||||
panic("failed to migrate model.ApiModel")
|
||||
log.Panic("failed to migrate model.ApiModel")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user