@@ -74,7 +74,7 @@ import (
7474type Container struct {
7575 projectID string
7676 db * gorm.DB
77- yugaByteDB * gorm.DB
77+ dedicatedDB * gorm.DB
7878 version string
7979 app * fiber.App
8080 eventDispatcher * services.EventDispatcher
@@ -209,47 +209,38 @@ func (container *Container) GormLogger() gormLogger.Interface {
209209 )
210210}
211211
212- // YugaByteDB creates an instance of gorm.DB if it has not been created already
213- func (container * Container ) YugaByteDB () (db * gorm.DB ) {
212+ // DedicatedDB creates an instance of gorm.DB if it has not been created already
213+ func (container * Container ) DedicatedDB () (db * gorm.DB ) {
214214 container .logger .Debug (fmt .Sprintf ("creating %T" , db ))
215- if container .yugaByteDB != nil {
216- return container .yugaByteDB
215+ if container .dedicatedDB != nil {
216+ return container .dedicatedDB
217217 }
218- //
219- //config := &gorm.Config{}
220- //if isLocal() {
221- // config = &gorm.Config{Logger: container.GormLogger()}
222- //}
223- //
224- //db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL_YUGABYTE")), config)
225- //if err != nil {
226- // container.logger.Fatal(err)
227- //}
228- //
229- //if err = db.Use(tracing.NewPlugin()); err != nil {
230- // container.logger.Fatal(stacktrace.Propagate(err, "cannot use GORM tracing plugin"))
231- //}
232- //
233- //sql, err := db.DB()
234- //if err != nil {
235- // container.logger.Fatal(err)
236- //}
237- //
238- //sql.SetMaxOpenConns(7)
239- //sql.SetMaxIdleConns(3)
240- //sql.SetConnMaxLifetime(time.Minute * 10)
241- //
242- //container.logger.Debug(fmt.Sprintf("Running migrations for yugabyte [%T]", db))
243- //if err = db.AutoMigrate(&entities.Heartbeat{}); err != nil {
244- // container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Heartbeat{})))
245- //}
246- //
247- //if err = db.AutoMigrate(&entities.HeartbeatMonitor{}); err != nil {
248- // container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.HeartbeatMonitor{})))
249- //}
250- //
251- //container.yugaByteDB = db
252- return container .yugaByteDB
218+
219+ config := & gorm.Config {}
220+ if isLocal () {
221+ config = & gorm.Config {Logger : container .GormLogger ()}
222+ }
223+
224+ db , err := gorm .Open (postgres .Open (os .Getenv ("DATABASE_URL_DEDICATED" )), config )
225+ if err != nil {
226+ container .logger .Fatal (err )
227+ }
228+
229+ if err = db .Use (tracing .NewPlugin ()); err != nil {
230+ container .logger .Fatal (stacktrace .Propagate (err , "cannot use GORM tracing plugin" ))
231+ }
232+
233+ container .logger .Debug (fmt .Sprintf ("Running migrations for yugabyte [%T]" , db ))
234+ if err = db .AutoMigrate (& entities.Heartbeat {}); err != nil {
235+ container .logger .Fatal (stacktrace .Propagate (err , fmt .Sprintf ("cannot migrate %T" , & entities.Heartbeat {})))
236+ }
237+
238+ if err = db .AutoMigrate (& entities.HeartbeatMonitor {}); err != nil {
239+ container .logger .Fatal (stacktrace .Propagate (err , fmt .Sprintf ("cannot migrate %T" , & entities.HeartbeatMonitor {})))
240+ }
241+
242+ container .dedicatedDB = db
243+ return container .dedicatedDB
253244}
254245
255246// DB creates an instance of gorm.DB if it has not been created already
@@ -706,7 +697,7 @@ func (container *Container) HeartbeatMonitorRepository() (repository repositorie
706697 return repositories .NewGormHeartbeatMonitorRepository (
707698 container .Logger (),
708699 container .Tracer (),
709- container .YugaByteDB (),
700+ container .DedicatedDB (),
710701 )
711702}
712703
@@ -1303,7 +1294,7 @@ func (container *Container) HeartbeatRepository() repositories.HeartbeatReposito
13031294 return repositories .NewGormHeartbeatRepository (
13041295 container .Logger (),
13051296 container .Tracer (),
1306- container .YugaByteDB (),
1297+ container .DedicatedDB (),
13071298 )
13081299}
13091300
0 commit comments