-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinitDb.js
More file actions
33 lines (27 loc) · 741 Bytes
/
initDb.js
File metadata and controls
33 lines (27 loc) · 741 Bytes
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
const { Sequelize } = require('sequelize');
const { DATABASE, USER, PASSWORD, HOST, PORT } = require('./env');
const sequelize = new Sequelize(DATABASE, USER, PASSWORD, {
host: HOST,
dialect: 'postgres',
port: PORT,
});
const initializeDb = async () => {
sequelize
.authenticate()
.then(() => {
console.log('Successfully connected to the database');
})
.catch((error) => {
console.log('Unable to connect to the database: ', error.message);
});
try {
await sequelize.sync({
force: false,
alter: false,
});
} catch (error) {
console.log('\x1b[31m%s\x1b[0m', `Error syncing: ${error.message}`);
}
};
exports.initializeDb = initializeDb;
exports.sequelize = sequelize;