forked from hpi-sam/digital-fuesim-manv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-source.ts
36 lines (33 loc) · 1.36 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
import { DataSource } from 'typeorm';
import { Config } from '../config';
import { ActionWrapperEntity } from './entities/action-wrapper.entity';
import { ExerciseWrapperEntity } from './entities/exercise-wrapper.entity';
import { AddExerciseAndActions1653554608164 } from './migrations/1653554608164-AddExerciseAndActions';
import { AddStateVersion1653601072020 } from './migrations/1653601072020-AddStateVersion';
export type DataSourceMode = 'baseline' | 'default' | 'testing';
export let testingDatabaseName: string;
export const createNewDataSource = (mode: DataSourceMode = 'default') => {
Config.initialize();
const defaultDatabaseName = `${Config.dbName}`;
testingDatabaseName = `${Config.dbName}_TESTING`;
return new DataSource({
type: 'postgres',
host: Config.dbHost,
port: Config.dbPort,
username: Config.dbUser,
password: Config.dbPassword,
database:
mode === 'baseline'
? // This database probably always exists
'postgres'
: mode === 'default'
? defaultDatabaseName
: testingDatabaseName,
entities: [ActionWrapperEntity, ExerciseWrapperEntity],
migrations: [
AddExerciseAndActions1653554608164,
AddStateVersion1653601072020,
],
logging: Config.dbLogging,
});
};