diff options
-rw-r--r-- | server.ts | 4 | ||||
-rw-r--r-- | server/initializers/database.ts | 17 |
2 files changed, 13 insertions, 8 deletions
@@ -70,7 +70,9 @@ if (CONFIG.CSP.ENABLED) { | |||
70 | // ----------- Database ----------- | 70 | // ----------- Database ----------- |
71 | 71 | ||
72 | // Initialize database and models | 72 | // Initialize database and models |
73 | import { initDatabaseModels } from './server/initializers/database' | 73 | import { initDatabaseModels, checkDatabaseConnectionOrDie } from './server/initializers/database' |
74 | checkDatabaseConnectionOrDie() | ||
75 | |||
74 | import { migrate } from './server/initializers/migrator' | 76 | import { migrate } from './server/initializers/migrator' |
75 | migrate() | 77 | migrate() |
76 | .then(() => initDatabaseModels(false)) | 78 | .then(() => initDatabaseModels(false)) |
diff --git a/server/initializers/database.ts b/server/initializers/database.ts index e05e7c335..a20cdacc3 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts | |||
@@ -77,13 +77,15 @@ const sequelizeTypescript = new SequelizeTypescript({ | |||
77 | } | 77 | } |
78 | }) | 78 | }) |
79 | 79 | ||
80 | sequelizeTypescript.authenticate() | 80 | function checkDatabaseConnectionOrDie () { |
81 | .then(() => logger.debug('Connection to PostgreSQL has been established successfully.')) | 81 | sequelizeTypescript.authenticate() |
82 | .catch(err => { | 82 | .then(() => logger.debug('Connection to PostgreSQL has been established successfully.')) |
83 | 83 | .catch(err => { | |
84 | logger.error('Unable to connect to PostgreSQL database.', { err }) | 84 | |
85 | process.exit(-1) | 85 | logger.error('Unable to connect to PostgreSQL database.', { err }) |
86 | }) | 86 | process.exit(-1) |
87 | }) | ||
88 | } | ||
87 | 89 | ||
88 | async function initDatabaseModels (silent: boolean) { | 90 | async function initDatabaseModels (silent: boolean) { |
89 | sequelizeTypescript.addModels([ | 91 | sequelizeTypescript.addModels([ |
@@ -140,6 +142,7 @@ async function initDatabaseModels (silent: boolean) { | |||
140 | 142 | ||
141 | export { | 143 | export { |
142 | initDatabaseModels, | 144 | initDatabaseModels, |
145 | checkDatabaseConnectionOrDie, | ||
143 | sequelizeTypescript | 146 | sequelizeTypescript |
144 | } | 147 | } |
145 | 148 | ||