forked from franpoh/groupproject2-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.js
63 lines (54 loc) · 1.39 KB
/
connect.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { Sequelize } = require("sequelize");
const sequelize = new Sequelize({
database: process.env.DATABASE,
username: process.env.USER_NAME,
password: process.env.PASSWORD,
host: process.env.DB_HOST,
port: 5432,
dialect: "postgres",
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false // in lieu of a CA for SSL, not recommended
}
},
});
async function testConnection() {
try {
await sequelize.authenticate();
console.log("Connection has been established successfully!");
return true;
} catch (error) {
console.log("Unable to connect to the database: ", error);
return false;
}
}
const Users = require ("./models/usersModel.js")(sequelize);
const Index = require ("./models/indexModel.js")(sequelize);
const Genres = require ("./models/genresModel.js")(sequelize);
const Reviews = require ("./models/reviewsModel.js")(sequelize);
const Swap = require ("./models/swapModel.js")(sequelize);
Index.belongsTo(Genres, {
foreignKey:"genreId"
});
Reviews.belongsTo(Users, {
foreignKey:"userId"
});
Reviews.belongsTo(Index, {
foreignKey:"indexId"
});
Swap.belongsTo(Users, {
foreignKey:"userId"
});
Swap.belongsTo(Index, {
foreignKey:"indexId"
});
module.exports = {
sequelize,
testConnection,
Users,
Index,
Swap,
Genres,
Reviews,
}