-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.config.js
37 lines (30 loc) · 1.1 KB
/
db.config.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
/************************************/
/*** Import des modules nécessaires */
const { Sequelize } = require('sequelize')
/************************************/
/*** Connexion à la base de données */
let sequelize = new Sequelize(
process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASS, {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
dialect: 'mysql',
logging: false
}
)
/*** Mise en place des relations */
const db = {}
db.sequelize = sequelize
db.User = require('./models/user')(sequelize)
db.Cocktail = require('./models/cocktail')(sequelize)
db.Groupe = require('./models/groupe')(sequelize)
db.User.hasMany(db.Cocktail, {foreignKey: 'user_id', onDelete: 'cascade'})
db.Cocktail.belongsTo(db.User, {foreignKey: 'user_id'})
db.User.belongsTo(db.Groupe, {foreignKey: 'groupe_id'})
// db.User.hasMany(db.Groupe, {foreignKey: 'user_id', onDelete: 'cascade'})
/*********************************/
/*** Synchronisation des modèles */
// sequelize.sync(err => {
// console.log('Database Sync Error', err)
// })
db.sequelize.sync({alter: true})
module.exports = db