summaryrefslogtreecommitdiff
path: root/trivionomicon/pkgs/socialpredict/0001-Support-POSTGRES_URL-for-overriding-the-PG-DSN.patch
blob: 69dc66088610107e9d5679aa8b0202f496a0563d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
From 67cf25f7cb397d37d807797b6013447b19c8f73b Mon Sep 17 00:00:00 2001
From: Alejandro Soto <alejandro@34project.org>
Date: Thu, 29 Jan 2026 23:21:21 -0600
Subject: [PATCH] Support POSTGRES_URL for overriding the PG DSN

---
 backend/util/postgres.go | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/util/postgres.go b/util/postgres.go
index ac69932..030f516 100644
--- a/util/postgres.go
+++ b/util/postgres.go
@@ -49,8 +49,11 @@ func InitDB() {
 		dbPort = "5432"
 	}
 
-	dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=UTC",
-		dbHost, dbUser, dbPassword, dbName, dbPort)
+	dsn := os.Getenv("POSTGRES_URL")
+	if dsn == "" {
+		dsn = fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=UTC",
+			dbHost, dbUser, dbPassword, dbName, dbPort)
+	}
 
 	DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
 	if err != nil {
-- 
2.51.2