diff options
author | buoyantair <buoyantair@protonmail.com> | 2018-11-20 12:28:13 +0530 |
---|---|---|
committer | buoyantair <buoyantair@protonmail.com> | 2018-11-20 12:28:13 +0530 |
commit | bc22d60899e14631cba0fb6450f4e85fc9528293 (patch) | |
tree | 285fa55033bc065df803adc2e4e3142fdfdd7309 /server/initializers/database.ts | |
parent | b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13 (diff) | |
parent | d216b5387fb774d1355df3ace002f7be469bd450 (diff) | |
download | PeerTube-bc22d60899e14631cba0fb6450f4e85fc9528293.tar.gz PeerTube-bc22d60899e14631cba0fb6450f4e85fc9528293.tar.zst PeerTube-bc22d60899e14631cba0fb6450f4e85fc9528293.zip |
Merge branch 'develop' of https://github.com/Chocobozzz/PeerTube into move-utils-to-shared
Diffstat (limited to 'server/initializers/database.ts')
-rw-r--r-- | server/initializers/database.ts | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/server/initializers/database.ts b/server/initializers/database.ts index dd5b9bf67..40cd659ab 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts | |||
@@ -119,25 +119,27 @@ export { | |||
119 | // --------------------------------------------------------------------------- | 119 | // --------------------------------------------------------------------------- |
120 | 120 | ||
121 | async function checkPostgresExtensions () { | 121 | async function checkPostgresExtensions () { |
122 | const extensions = [ | 122 | const promises = [ |
123 | 'pg_trgm', | 123 | checkPostgresExtension('pg_trgm'), |
124 | 'unaccent' | 124 | checkPostgresExtension('unaccent') |
125 | ] | 125 | ] |
126 | 126 | ||
127 | for (const extension of extensions) { | 127 | return Promise.all(promises) |
128 | const query = `SELECT true AS enabled FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;` | 128 | } |
129 | const [ res ] = await sequelizeTypescript.query(query, { raw: true }) | 129 | |
130 | async function checkPostgresExtension (extension: string) { | ||
131 | const query = `SELECT true AS enabled FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;` | ||
132 | const [ res ] = await sequelizeTypescript.query(query, { raw: true }) | ||
130 | 133 | ||
131 | if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) { | 134 | if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) { |
132 | // Try to create the extension ourself | 135 | // Try to create the extension ourself |
133 | try { | 136 | try { |
134 | await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true }) | 137 | await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true }) |
135 | 138 | ||
136 | } catch { | 139 | } catch { |
137 | const errorMessage = `You need to enable ${extension} extension in PostgreSQL. ` + | 140 | const errorMessage = `You need to enable ${extension} extension in PostgreSQL. ` + |
138 | `You can do so by running 'CREATE EXTENSION ${extension};' as a PostgreSQL super user in ${CONFIG.DATABASE.DBNAME} database.` | 141 | `You can do so by running 'CREATE EXTENSION ${extension};' as a PostgreSQL super user in ${CONFIG.DATABASE.DBNAME} database.` |
139 | throw new Error(errorMessage) | 142 | throw new Error(errorMessage) |
140 | } | ||
141 | } | 143 | } |
142 | } | 144 | } |
143 | } | 145 | } |