Only try to create the schema if it doesn't already exist

Signed-off-by: Irmo van den Berge <i.vdberge@valtes.nl>
pull/6708/head
Irmo van den Berge 9 months ago
parent a81f5c10c6
commit 8f56a515cb

@ -190,7 +190,15 @@ module.exports = {
// -> Create DB Schema if different than the default 'public'
async createDefaultSchema () {
if (WIKI.config.db.schema && WIKI.config.db.schema !== 'public') {
await self.knex.raw(`CREATE SCHEMA IF NOT EXISTS ${WIKI.config.db.schema};`)
// Don't create the schema if it already exists. This avoids errors
// when the user lacks permission to create new schemas while the schema
// already exists.
let matched_schemas = await self.knex.select('schema_name')
.from('information_schema.schemata')
.where('schema_name', WIKI.config.db.schema);
if (matched_schemas.length == 0) {
await self.knex.raw(`CREATE SCHEMA IF NOT EXISTS ${WIKI.config.db.schema};`)
}
}
},
// -> Migrate DB Schemas

Loading…
Cancel
Save