-
Notifications
You must be signed in to change notification settings - Fork 0
/
ormconfig.js
56 lines (47 loc) · 1.61 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
55
56
require("dotenv").config();
// isso serve apenas para executar as migrations em produção!
// Roda durante o typeorm migration:run
// can't change to .json because of process.env variables and
// you can't have separated files because CLI commands uses ormconfig.js at root
// if dev mode...
/** @type {import("typeorm").ConnectionOptions} */
let ormconfig = {
type: "postgres",
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT),
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: "endoh.io",
entities: [__dirname + "/src/entities/**/*.ts"],
synchronize: false, // set as 'true' if you're syncronizing for the first time
migrations: [__dirname + "/src/migrations/**/*.ts"],
subscribers: [__dirname + "/src/subscriber/**/*Subscriber.ts"],
cli: {
entitiesDir: "src/entities",
migrationsDir: "src/migrations",
subscribersDir: "src/subscriber",
},
logging: ["error"],
};
if (process.env.NODE_ENV === "production") {
ormconfig = {
...ormconfig,
entities: [__dirname + "/build/entities/**/*.js"],
migrations: [__dirname + "/build/migrations/**/*.js"],
subscribers: [__dirname + "/build/subscriber/**/*Subscriber.js"],
cli: {
entitiesDir: __dirname + "build/src/entities",
migrationsDir: __dirname + "build/src/migrations",
subscribersDir: __dirname + "build/src/subscriber",
},
};
}
if (process.env.NODE_ENV === "test") {
ormconfig = {
...ormconfig,
database: "endoh.io-test",
synchronize: true,
dropSchema: true,
};
}
module.exports = ormconfig;