Verified Commit c3c05451 authored by les's avatar les
Browse files

change how db its initialized

parent 5e0e0848
const sequelize = require('./index')
const sequelize = require('./index').sequelize
const { Model, DataTypes } = require('sequelize')
class Announcement extends Model {}
......
const sequelize = require('./index')
const sequelize = require('./index').sequelize
const { Model, DataTypes } = require('sequelize')
class APUser extends Model {}
......
const config = require('config')
const config = require('../../config')
const moment = require('dayjs')
const { htmlToText } = require('html-to-text')
const { Model, DataTypes } = require('sequelize')
const SequelizeSlugify = require('sequelize-slugify')
const sequelize = require('./index')
const sequelize = require('./index').sequelize
const Resource = require('./resource')
const Notification = require('./notification')
......
const sequelize = require('./index')
const sequelize = require('./index').sequelize
const { Model, DataTypes } = require('sequelize')
class EventNotification extends Model {}
......
// const fs = require('fs')
// const path = require('path')
const Sequelize = require('sequelize')
// const basename = path.basename(__filename)
const config = require('config')
const consola = require('consola')
// const db = {}
let sequelize = null
const config = require('../../config')
const log = require('../../log')
try {
sequelize = new Sequelize(config.db)
} catch (e) {
consola.warn(` ⚠️ Cannot connect to db, check your configuration => ${e}`)
process.exit(-1)
const db = {
sequelize: null,
close () {
return db.sequelize.close()
},
async connect (dbConf = config.db) {
log.debug(`Connecting to DB: ${dbConf}`)
db.sequelize = new Sequelize(dbConf)
await db.sequelize.authenticate()
return db.sequelize
}
}
sequelize.authenticate().catch(e => {
consola.error(' ⚠ Error connecting to DB: ', String(e))
process.exit(-1)
})
// fs
// .readdirSync(__dirname)
// .filter(file => {
// return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js')
// })
// .forEach(file => {
// const model = sequelize.import(path.join(__dirname, file))
// db[model.name] = model
// })
// Object.keys(db).forEach(modelName => {
// if (db[modelName].associate) {
// db[modelName].associate(db)
// }
// })
// db.sequelize = sequelize
// db.Sequelize = Sequelize
if (!config.firstrun) {
try {
db.connect()
} catch (e) {
log.warn(` ⚠️ Cannot connect to db, check your configuration => ${e}`)
process.exit(1)
}
}
module.exports = sequelize
module.exports = db
const sequelize = require('./index')
const sequelize = require('./index').sequelize
const { Model, DataTypes } = require('sequelize')
const APUser = require('./ap_user')
......
const sequelize = require('./index')
const sequelize = require('./index').sequelize
const { Model, DataTypes } = require('sequelize')
class Notification extends Model {}
......
const sequelize = require('./index')
const sequelize = require('./index').sequelize
const { Model, DataTypes } = require('sequelize')
class OAuthClient extends Model {}
......
const sequelize = require('./index')
const sequelize = require('./index').sequelize
const { Model, DataTypes } = require('sequelize')
const User = require('./user')
......
const sequelize = require('./index')
const sequelize = require('./index').sequelize
const { Model, DataTypes } = require('sequelize')
const User = require('./user')
......
const { Model, DataTypes } = require('sequelize')
const sequelize = require('./index')
const sequelize = require('./index').sequelize
class Place extends Model {}
......
const { Model, DataTypes } = require('sequelize')
const sequelize = require('./index')
const sequelize = require('./index').sequelize
// const Event = require('./event')
const APUser = require('./ap_user')
class Resource extends Model {}
......
const { Model, DataTypes } = require('sequelize')
const sequelize = require('./index')
const sequelize = require('./index').sequelize
class Setting extends Model {}
......
const { Model, DataTypes } = require('sequelize')
const sequelize = require('./index')
const sequelize = require('./index').sequelize
class Tag extends Model {}
......
const bcrypt = require('bcryptjs')
const { Model, DataTypes } = require('sequelize')
const sequelize = require('./index')
const sequelize = require('./index').sequelize
class User extends Model {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment