-
Notifications
You must be signed in to change notification settings - Fork 0
/
ormconfig.js
54 lines (50 loc) · 1.54 KB
/
ormconfig.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { ConfigService } = require("@nestjs/config");
const config = new ConfigService();
console.log(`Running on <${config.get("NODE_ENV")}> Mode:\n`);
var dbConfig = {
synchronize: false,
migrations: ["migrations/*.js"],
cli: {
migrationsDir: "migrations",
},
};
switch (config.get("NODE_ENV")) {
case "development":
Object.assign(dbConfig, {
type: "sqlite",
database: "db.sqlite",
entities: ["**/*.entity.js"],
});
break;
case "test":
Object.assign(dbConfig, {
type: "sqlite",
database: "test.sqlite",
entities: ["**/*.entity.ts"],
migrationsRun: true,
});
break;
case "production":
Object.assign(dbConfig, {
// configuration for render database
type: "postgres",
host: config.get("Hostname"),
port: 5432,
username: config.get("Username"),
password: config.get("Password"),
database: config.get("Database"),
entities: ["**/*.entity.js"],
logging: false,
extra: {
ssl: {
rejectUnauthorized: false, // Set to true if you want to enforce certificate validation
},
},
// Dynamically select the connection string based on the environment
url: config.get("External_Database_URL"),
});
break;
default:
throw new Error("unknown environment");
}
module.exports = dbConfig;