mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 03:29:37 +02:00
Server db utils changes
This commit is contained in:
parent
91e99e1bcc
commit
d86ebe3e58
5 changed files with 36 additions and 21 deletions
|
@ -1,8 +1,9 @@
|
|||
const { Sequelize } = require('sequelize');
|
||||
const { join } = require('path');
|
||||
const Umzug = require('umzug');
|
||||
const backupDB = require('./utils/backupDb');
|
||||
|
||||
// Utils
|
||||
const backupDB = require('./utils/backupDb');
|
||||
const Logger = require('../utils/Logger');
|
||||
const logger = new Logger();
|
||||
|
||||
|
@ -28,15 +29,16 @@ const connectDB = async () => {
|
|||
backupDB();
|
||||
|
||||
await sequelize.authenticate();
|
||||
logger.log('Connected to database');
|
||||
|
||||
// migrations
|
||||
// execute all pending migrations
|
||||
const pendingMigrations = await umzug.pending();
|
||||
|
||||
if (pendingMigrations.length > 0) {
|
||||
logger.log('Executing pending migrations');
|
||||
await umzug.up();
|
||||
}
|
||||
|
||||
logger.log('Connected to database');
|
||||
} catch (error) {
|
||||
logger.log(`Unable to connect to the database: ${error.message}`, 'ERROR');
|
||||
process.exit(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue