2020-04-12 07:11:06 -04:00
|
|
|
import { Sequelize } from 'sequelize-typescript'
|
2020-04-12 07:52:50 -04:00
|
|
|
import { cloneDeep } from 'lodash'
|
2020-04-12 07:11:06 -04:00
|
|
|
import { Author } from './author'
|
|
|
|
import { Note } from './note'
|
|
|
|
import { Revision } from './revision'
|
|
|
|
import { Temp } from './temp'
|
|
|
|
import { User } from './user'
|
|
|
|
import { logger } from '../logger'
|
|
|
|
import { config } from '../config'
|
|
|
|
|
|
|
|
const dbconfig = cloneDeep(config.db)
|
2020-04-12 07:52:50 -04:00
|
|
|
dbconfig.logging = config.debug ? (data): void => {
|
2019-04-12 00:05:32 -04:00
|
|
|
logger.info(data)
|
|
|
|
} : false
|
2016-12-11 21:18:12 -05:00
|
|
|
|
2020-04-12 07:52:50 -04:00
|
|
|
export let sequelize: Sequelize
|
2016-12-22 00:23:17 -05:00
|
|
|
|
2016-12-22 06:42:00 -05:00
|
|
|
// Heroku specific
|
2018-03-07 09:17:35 -05:00
|
|
|
if (config.dbURL) {
|
|
|
|
sequelize = new Sequelize(config.dbURL, dbconfig)
|
2017-03-08 05:45:51 -05:00
|
|
|
} else {
|
|
|
|
sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig)
|
|
|
|
}
|
2016-04-20 06:03:55 -04:00
|
|
|
|
2020-04-12 07:11:06 -04:00
|
|
|
sequelize.addModels([Author, Note, Revision, Temp, User])
|
2020-04-11 06:13:37 -04:00
|
|
|
|
2020-04-12 07:11:06 -04:00
|
|
|
export { Author, Note, Revision, Temp, User }
|