forked from terrestris/gondolin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequelize.ts
36 lines (30 loc) · 916 Bytes
/
sequelize.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
'use strict';
import { Sequelize } from 'sequelize-typescript';
import dataBaseConfig from './config/database';
import logger from './config/logger';
const environment = process.env.NODE_ENV || 'production';
const config = dataBaseConfig[environment];
const modelsPath = __dirname + '/models';
const belongsToManyPath = __dirname + '/models/belongsToMany';
logger.debug(`Starting database intialization with environment ${environment}.`);
// Main
const sequelize = new Sequelize({
modelPaths: [
modelsPath,
belongsToManyPath
],
...config
});
// Sync database schemas
// Main
sequelize.createSchema(config.schema, {})
.then(() => {
sequelize.sync();
})
.then(() => {
logger.info(`Database (schema ${config.schema}) synchronized.`);
})
.catch((err: Error) => {
logger.error(`Database (schema ${config.schema}) synchronization failed: ${err}`);
});
export default sequelize;