aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/database.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-11-19 15:21:09 +0100
committerChocobozzz <me@florianbigard.com>2018-11-19 15:21:09 +0100
commit0b2f03d3712f438f67eccf86b67acd047284f9b4 (patch)
treeb6ae2ca2405d6a915e6be34e1d3c4e04312f6f03 /server/initializers/database.ts
parent361805c48b14c5402c9984485c67c45a1a3113cc (diff)
downloadPeerTube-0b2f03d3712f438f67eccf86b67acd047284f9b4.tar.gz
PeerTube-0b2f03d3712f438f67eccf86b67acd047284f9b4.tar.zst
PeerTube-0b2f03d3712f438f67eccf86b67acd047284f9b4.zip
Speedup peertube startup
Diffstat (limited to 'server/initializers/database.ts')
-rw-r--r--server/initializers/database.ts32
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
121async function checkPostgresExtensions () { 121async 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
130async 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}