aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/initializers/database.ts32
-rw-r--r--server/initializers/installer.ts21
-rw-r--r--server/lib/user.ts15
3 files changed, 43 insertions, 25 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}
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts
index c952ad46c..b9a9da183 100644
--- a/server/initializers/installer.ts
+++ b/server/initializers/installer.ts
@@ -12,12 +12,21 @@ import { remove, ensureDir } from 'fs-extra'
12 12
13async function installApplication () { 13async function installApplication () {
14 try { 14 try {
15 await sequelizeTypescript.sync() 15 await Promise.all([
16 await removeCacheDirectories() 16 // Database related
17 await createDirectoriesIfNotExist() 17 sequelizeTypescript.sync()
18 await createApplicationIfNotExist() 18 .then(() => {
19 await createOAuthClientIfNotExist() 19 return Promise.all([
20 await createOAuthAdminIfNotExist() 20 createApplicationIfNotExist(),
21 createOAuthClientIfNotExist(),
22 createOAuthAdminIfNotExist()
23 ])
24 }),
25
26 // Directories
27 removeCacheDirectories()
28 .then(() => createDirectoriesIfNotExist())
29 ])
21 } catch (err) { 30 } catch (err) {
22 logger.error('Cannot install application.', { err }) 31 logger.error('Cannot install application.', { err })
23 process.exit(-1) 32 process.exit(-1)
diff --git a/server/lib/user.ts b/server/lib/user.ts
index db29469eb..acb883e23 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -17,8 +17,10 @@ async function createUserAccountAndChannel (userToCreate: UserModel, validateUse
17 validate: validateUser 17 validate: validateUser
18 } 18 }
19 19
20 const userCreated = await userToCreate.save(userOptions) 20 const [ userCreated, accountCreated ] = await Promise.all([
21 const accountCreated = await createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t) 21 userToCreate.save(userOptions),
22 createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t)
23 ])
22 userCreated.Account = accountCreated 24 userCreated.Account = accountCreated
23 25
24 let channelName = userCreated.username + '_channel' 26 let channelName = userCreated.username + '_channel'
@@ -37,8 +39,13 @@ async function createUserAccountAndChannel (userToCreate: UserModel, validateUse
37 return { user: userCreated, account: accountCreated, videoChannel } 39 return { user: userCreated, account: accountCreated, videoChannel }
38 }) 40 })
39 41
40 account.Actor = await setAsyncActorKeys(account.Actor) 42 const [ accountKeys, channelKeys ] = await Promise.all([
41 videoChannel.Actor = await setAsyncActorKeys(videoChannel.Actor) 43 setAsyncActorKeys(account.Actor),
44 setAsyncActorKeys(videoChannel.Actor)
45 ])
46
47 account.Actor = accountKeys
48 videoChannel.Actor = channelKeys
42 49
43 return { user, account, videoChannel } as { user: UserModel, account: AccountModel, videoChannel: VideoChannelModel } 50 return { user, account, videoChannel } as { user: UserModel, account: AccountModel, videoChannel: VideoChannelModel }
44} 51}