-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathindex.js
37 lines (31 loc) · 979 Bytes
/
index.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
const Sequelize = require('sequelize')
const env = process.env.NODE_ENV || 'development'
const config = require('../../db/config.json')[env]
const { logger } = require('probot/lib/logger')
const InstallationModel = require('./installation')
const SubscriptionModel = require('./subscription')
Object.assign(config, {
operatorsAliases: false,
benchmark: true,
logging: (query, ms) => {
logger.debug({ ms }, query)
}
})
let sequelize
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config)
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config)
}
const models = {
Installation: InstallationModel.init(sequelize, Sequelize),
Subscription: SubscriptionModel.init(sequelize, Sequelize)
}
Object.values(models)
.filter(model => typeof model.associate === 'function')
.forEach(model => model.associate(models))
module.exports = {
...models,
sequelize,
Sequelize
}