-
Notifications
You must be signed in to change notification settings - Fork 0
/
orm-master.config.ts
68 lines (62 loc) · 2.29 KB
/
orm-master.config.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const NODE_ENV = process.env.NODE_ENV || 'development';
if (!process.env.DB_MAIN_DATABASE) {
require('dotenv').config({
path: path.resolve(__dirname, `./.env.${NODE_ENV}`),
});
}
const distPrefix = process.env.NODE_ENV === 'test' ? '' : '/dist';
// https://stackoverflow.com/questions/59435293/typeorm-entity-in-nestjs-cannot-use-import-statement-outside-a-module
// If you are using an ormconfig.json instead, you should use
// entities: ["dist/**/*.entity.js"]
// so that you are using the compiled js files and have no chance to use the ts files in your code.
// To use typeorm-seeding, we need to use dist/js files for nestjs and use ts files for tests
// To prevent the issue with the typeorm migration cli which reads orm.environments.ts by default, named it differently - orm-master.environments.js
console.log(
'orm-master.environments.js',
'NODE_ENV',
NODE_ENV,
// 'DB_MAIN_HOST',
// process.env.DB_MAIN_HOST,
// 'DB_MAIN_PORT',
// process.env.DB_MAIN_PORT,
// 'DB_MAIN_USERNAME_MASTER',
// process.env.DB_MAIN_USERNAME_MASTER,
// 'DB_MAIN_PASSWORD_MASTER',
// process.env.DB_MAIN_PASSWORD_MASTER,
'DB_MAIN_DATABASE',
process.env.DB_MAIN_DATABASE,
);
module.exports = {
name: 'MASTER_CONNECTION_CONF',
type: 'postgres',
host: process.env.DB_MAIN_HOST,
port: Number(process.env.DB_MAIN_PORT),
username: process.env.DB_MAIN_USERNAME_MASTER,
password: process.env.DB_MAIN_PASSWORD_MASTER,
database: process.env.DB_MAIN_DATABASE,
synchronize: false,
dropSchema: false,
logging: false,
// entities: ['./src/oem/**/*.entity{.ts,.js}'],
entities: [
path.join(__dirname, `.${distPrefix}/src/oem/**/*.entity{.ts,.js}`),
],
// migrations: ['./src/oem/migrations/**/*{.ts,.js}}'],
migrations: [
path.join(__dirname, `.${distPrefix}/src/oem/migrations/**/*{.ts,.js}}`),
],
// seeds: ['./src/oem/seeds/index.seed{.ts,.js}'],
seeds: [
path.join(__dirname, `.${distPrefix}/src/oem/seeds/index.seed{.ts,.js}`),
],
// factories: ['./src/oem/**/*.factory{.ts,.js}'],
factories: [
path.join(__dirname, `.${distPrefix}/src/oem/**/*.factory{.ts,.js}`),
],
cli: {
// migrationsDir: './src/oem/migrations',
migrationsDir: `.${distPrefix}/src/oem/migrations`,
},
};