-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (33 loc) · 866 Bytes
/
index.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
require('dotenv').config()
const C = require('./model/Connector')
// Set globally the connector to make db request
global.Connector = new C()
const start = async (retried) => {
if (process.env.autoMigrate && retried) {
// Migrate DB up if new migrations are needed and available
await Connector.migrateDB()
}
// Test the integrity of the db.
try {
await Connector.checkIntegrity()
console.log('✅ DB checked')
if (process.env.telegramToken) {
// Load telegram bot
require('./telegram')
console.log('✅ Telegram Bot loaded')
}
} catch (err) {
console.error(err)
if (err.code) {
// Handle
if (retried) {
console.log('⛔️ Could not init properly the DB')
process.exit(1)
} else {
await Connector.initDB()
await start(true)
}
}
}
}
start()