mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
change how db its initialized
This commit is contained in:
parent
5e0e08480a
commit
c3c05451db
15 changed files with 37 additions and 52 deletions
|
@ -1,4 +1,4 @@
|
|||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
|
||||
class Announcement extends Model {}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
|
||||
class APUser extends Model {}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
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')
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
|
||||
class EventNotification extends Model {}
|
||||
|
|
|
@ -1,41 +1,27 @@
|
|||
// 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)
|
||||
})
|
||||
if (!config.firstrun) {
|
||||
try {
|
||||
db.connect()
|
||||
} catch (e) {
|
||||
log.warn(` ⚠️ Cannot connect to db, check your configuration => ${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
|
||||
|
||||
module.exports = sequelize
|
||||
module.exports = db
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
const APUser = require('./ap_user')
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
|
||||
class Notification extends Model {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
|
||||
class OAuthClient extends Model {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
|
||||
const User = require('./user')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
|
||||
const User = require('./user')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const { Model, DataTypes } = require('sequelize')
|
||||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
|
||||
class Place extends Model {}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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 {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const { Model, DataTypes } = require('sequelize')
|
||||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
|
||||
class Setting extends Model {}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const { Model, DataTypes } = require('sequelize')
|
||||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
|
||||
class Tag extends Model {}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
const bcrypt = require('bcryptjs')
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
const sequelize = require('./index')
|
||||
const sequelize = require('./index').sequelize
|
||||
|
||||
class User extends Model {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue