-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathormconfig.js
33 lines (27 loc) · 893 Bytes
/
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
/**
* @file Manages the configuration settings for the TypeORM.
*/
const { DataSource } = require("typeorm");
const runningMigration = process.argv.length >= 3 && process.argv[2].includes('migration');
const runningTSMain = process.argv[1].includes('main.ts');
const models = [
'channel.model',
'filter.model',
'wormhole.model',
];
const connectionOptions = {
database: 'data/therabot.db',
type: 'better-sqlite3',
};
connectionOptions.entities = models.map((model) =>
runningMigration || runningTSMain ? `src/models/${model}.ts` : `dist/models/${model}.js`
);
if (runningMigration) {
connectionOptions.cli = {
migrationsDir: 'migrations',
};
connectionOptions.migrations = ['migrations/*.ts'];
connectionOptions.migrationsTableName = 'migrations';
}
const dataSource = new DataSource(connectionOptions);
module.exports = { dataSource };