LifeMate — Personal, Family & Learning Companion
fix: support private PostgreSQL staging connections
davoodmehraban89 committed
Oct 5, 2026 at 15:19 UTC
d8cf68d750d095f08aa2d894df48bd4c6e10773f
1 file changed
+21
-6
backend/scripts/migrate.js
+21
-6
@@ -4,12 +4,27 @@ import pg from 'pg';
4
5
const { Client } = pg;
6
const databaseUrl = process.env.DATABASE_URL;
7
-if (!databaseUrl) throw new Error('DATABASE_URL is required');
8
-
9
-const client = new Client({
10
- connectionString: databaseUrl,
11
- ssl: databaseUrl.includes('localhost') ? false : { rejectUnauthorized: false },
12
-});
7
+const client = new Client(
8
+ databaseUrl
9
+ ? {
10
+ connectionString: databaseUrl,
11
+ ssl:
12
+ process.env.PGSSLMODE === 'require'
13
+ ? { rejectUnauthorized: false }
14
+ : false,
15
+ }
16
+ : {
17
+ host: process.env.PGHOST,
18
+ port: Number(process.env.PGPORT ?? 5432),
19
+ database: process.env.PGDATABASE,
20
+ user: process.env.PGUSER,
21
+ password: process.env.PGPASSWORD,
22
+ ssl:
23
+ process.env.PGSSLMODE === 'require'
24
+ ? { rejectUnauthorized: false }
25
+ : false,
26
+ },
27
+);
28
29
await client.connect();
30
try {