aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server.ts4
-rw-r--r--server/initializers/database.ts17
2 files changed, 13 insertions, 8 deletions
diff --git a/server.ts b/server.ts
index 1286cf521..e83fabb98 100644
--- a/server.ts
+++ b/server.ts
@@ -70,7 +70,9 @@ if (CONFIG.CSP.ENABLED) {
70// ----------- Database ----------- 70// ----------- Database -----------
71 71
72// Initialize database and models 72// Initialize database and models
73import { initDatabaseModels } from './server/initializers/database' 73import { initDatabaseModels, checkDatabaseConnectionOrDie } from './server/initializers/database'
74checkDatabaseConnectionOrDie()
75
74import { migrate } from './server/initializers/migrator' 76import { migrate } from './server/initializers/migrator'
75migrate() 77migrate()
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
80sequelizeTypescript.authenticate() 80function 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
88async function initDatabaseModels (silent: boolean) { 90async function initDatabaseModels (silent: boolean) {
89 sequelizeTypescript.addModels([ 91 sequelizeTypescript.addModels([
@@ -140,6 +142,7 @@ async function initDatabaseModels (silent: boolean) {
140 142
141export { 143export {
142 initDatabaseModels, 144 initDatabaseModels,
145 checkDatabaseConnectionOrDie,
143 sequelizeTypescript 146 sequelizeTypescript
144} 147}
145 148