Skip to content

Commit

Permalink
fix db connect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vramk23 committed May 29, 2024
1 parent 2c987ad commit 274a240
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions capten/common-pkg/postgres/db-init/db_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
var log = logging.NewLogger()

type DBConfig struct {
DBAddr string `envconfig:"PG_DB_HOST" required:"true"`
DBHost string `envconfig:"PG_DB_HOST" required:"true"`
DBPort string `envconfig:"PG_DB_PORT" default:"5432"`
DBName string `envconfig:"PG_DB_NAME" required:"true"`
EntityName string `envconfig:"PG_DB_ENTITY_NAME" default:"postgres"`
Expand All @@ -55,20 +55,17 @@ func RunMigrations(mode Mode) error {
}

func RunMigrationsWithConfig(conf *DBConfig, mode Mode) error {
dbConnectionString, err := getDbConnectionURLFromDbType(conf, conf.Password)
if err != nil {
return errors.WithMessage(err, "DB connection Url create failed")
}

dbConnectionString := getDbConnectionURLFromDbType(conf, conf.Password)
log.Infof("DB connection string: %s", dbConnectionString)
if err := runMigrations(conf.SourceURI, dbConnectionString, conf.DBName, mode); err != nil {
return err
}
return nil
}

func getDbConnectionURLFromDbType(conf *DBConfig, password string) (string, error) {
return fmt.Sprintf("postgres://%s:%s@%s:%v/%s?sslmode=disable",
conf.Username, password, conf.DBAddr, conf.DBPort, conf.DBName), nil
func getDbConnectionURLFromDbType(conf *DBConfig, password string) string {
return fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=disable",
conf.Username, password, conf.DBHost, conf.DBPort, conf.DBName)
}

func runMigrations(sourceURL, databaseURL, dbName string, mode Mode) (err error) {
Expand Down

0 comments on commit 274a240

Please sign in to comment.