Skip to content

Commit

Permalink
Merge pull request #35 from Ferlab-Ste-Justine/feat/cin-3377-db-migra…
Browse files Browse the repository at this point in the history
…tion

feat: CLIN-3377 - migration after QA
  • Loading branch information
creativeyann17 authored Feb 19, 2025
2 parents c45bf19 + 25a1575 commit 595d08e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions backend/internal/database/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package database
import (
"fmt"
"log"
"net/url"
"os"
"time"

Expand Down Expand Up @@ -58,16 +59,16 @@ func NewPostgresDB() (*gorm.DB, error) {

func MigrateWithParams(path string, host string, port string, database string, user string, password string, sslmode string, sslcert string) {
log.Print("Migrating postgres database...")
url := fmt.Sprintf("postgres://%s:%s/%s?user=%s&password=%s", host, port, database, user, password)
conn := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?", user, url.QueryEscape(password), host, port, database)
if sslmode != "" {
url += fmt.Sprintf("&sslmode=%s", sslmode)
conn += fmt.Sprintf("&sslmode=%s", sslmode)
}
if sslcert != "" {
url += fmt.Sprintf("&sslrootcert=%s", sslcert)
conn += fmt.Sprintf("&sslrootcert=%s", url.QueryEscape(sslcert))
}
m, err := migrate.New(
path,
url,
conn,
)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 595d08e

Please sign in to comment.