-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb-sync.js
More file actions
26 lines (24 loc) · 825 Bytes
/
db-sync.js
File metadata and controls
26 lines (24 loc) · 825 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
const models = require('./models')
const chalk = require('chalk')
let main = async () => {
// Проверяем соединие с БД
try {
await models.sequelize.authenticate()
console.log(chalk.green('Connection to DB established'))
} catch (err) {
console.log(chalk.red('Error occured when connection to DB: ', err.parent.sqlMessage))
return
}
// Синхронизируем модели
try {
await models.sequelize.sync({force: true})
console.log(chalk.green('Models synced successfuly'))
} catch (err) {
console.log(chalk.red('Error occured when syncing DB: ', err.parent.sqlMessage))
return
} finally {
console.log(chalk.green('Closing connection...'))
await models.sequelize.close()
}
}
main()