-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-source.ts
39 lines (34 loc) · 1.32 KB
/
data-source.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
import 'dotenv/config';
import { DataSource, DataSourceOptions } from 'typeorm';
export const getDataSourceOptions = (): DataSourceOptions => {
const isProduction = process.env.NODE_ENV === 'production';
const shouldSync = isProduction
? false
: process.env.PG_SYNCHRONIZE === 'true';
const shouldLog = process.env.PG_LOGGING === 'true';
return {
type: 'postgres',
host: process.env.PG_HOST,
port: Number(process.env.PG_PORT),
database: process.env.PG_DATABASE,
username: process.env.PG_USERNAME,
password: process.env.PG_PASSWORD,
// This will be false when going to production
synchronize: shouldSync,
logging: shouldLog,
// FOR development and deployment
entities: ['dist/**/*.entity{.ts,.js}'],
// FOR end to end testing
//entities: ['src/**/*.entity{.ts,.js}'],
// Generating a migration: npm run migration:generate -n src/database/migrations/[NameOfMigration]
// FOR development and deployment
// migrations: ['src/database/migrations/*{.ts,.js}'],
migrations: ['dist/database/migrations/*{.ts,.js}'],
// FOR end to end testing
//migrations: ['src/database/migrations/*{.ts,.js}'],
migrationsTableName: 'migrations_typeorm',
migrationsRun: false,
};
};
const dataSource = new DataSource(getDataSourceOptions());
export default dataSource;