-
Notifications
You must be signed in to change notification settings - Fork 0
/
ormconfig.ts
33 lines (28 loc) · 1.36 KB
/
ormconfig.ts
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
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { join } = require('path'); // eslint-disable-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type,consistent-return
function getDatabaseUrl() {
if (process.env.DB_URL) return process.env.DB_URL;
if (process.env.DB_USER && process.env.DB_PASSWORD && process.env.DB_HOST && process.env.DB_DATABASE) {
// eslint-disable-next-line max-len
return `postgres://${process.env.DB_USER}:${process.env.DB_PASSWORD}@${process.env.DB_HOST}/${process.env.DB_DATABASE}`;
}
return undefined;
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
function getRootDir() {
return join(__dirname, 'src');
}
module.exports = {
type: 'postgres',
url: getDatabaseUrl(),
schema: process.env.DB_SCHEMA || 'public',
entities: [join(getRootDir(), 'infrastructure/persistence/typeorm/entities/*')],
migrations: [join(getRootDir(), 'infrastructure/persistence/typeorm/migrations/*')],
synchronize: false, // Database changes should only happen via migration scripts.
cli: {
migrationsDir: join(getRootDir(), 'infrastructure/persistence/typeorm/migrations/*'),
},
ssl: process.env.DB_SSL === undefined ? process.env.NODE_ENV === 'production' : !!process.env.DB_SSL,
};