Skip to content

Commit

Permalink
Merge pull request #1691 from stakwork/feat/test_db_connection
Browse files Browse the repository at this point in the history
Added Configuration For Test Postgres DB
  • Loading branch information
elraphty authored Jun 14, 2024
2 parents ee24492 + b47d144 commit 479636a
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions db/test_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package db

import (
"fmt"

"github.com/rs/xid"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)

var TestDB database

func InitTestDB() {
rdsHost := "test_db"
rdsPort := fmt.Sprintf("%d", 5532)
rdsDbName := "test_posrgres"
rdsUsername := "test_user"
rdsPassword := "test_password"
dbURL := fmt.Sprintf("postgres://%s:%s@%s:%s/%s", rdsUsername, rdsPassword, rdsHost, rdsPort, rdsDbName)

if dbURL == "" {
panic("TESTDB URL is not set")
}

var err error

db, err := gorm.Open(postgres.New(postgres.Config{
DSN: dbURL,
PreferSimpleProtocol: true,
}), &gorm.Config{})

if err != nil {
panic(err)
}

TestDB.db = db

fmt.Println("db connected")

// migrate table changes
db.AutoMigrate(&Tribe{})
db.AutoMigrate(&Person{})
db.AutoMigrate(&Channel{})
db.AutoMigrate(&LeaderBoard{})
db.AutoMigrate(&ConnectionCodes{})
db.AutoMigrate(&BountyRoles{})
db.AutoMigrate(&UserInvoiceData{})
db.AutoMigrate(&WorkspaceRepositories{})
db.AutoMigrate(&WorkspaceFeatures{})
db.AutoMigrate(&FeaturePhase{})
db.AutoMigrate(&FeatureStory{})
db.AutoMigrate(&NewBounty{})
db.AutoMigrate(&BudgetHistory{})
db.AutoMigrate(&NewPaymentHistory{})
db.AutoMigrate(&NewInvoiceList{})
db.AutoMigrate(&NewBountyBudget{})
db.AutoMigrate(&Workspace{})
db.AutoMigrate(&WorkspaceUsers{})
db.AutoMigrate(&WorkspaceUserRoles{})

people := TestDB.GetAllPeople()
for _, p := range people {
if p.Uuid == "" {
TestDB.AddUuidToPerson(p.ID, xid.New().String())
}
}
}

0 comments on commit 479636a

Please sign in to comment.