Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix postgres db custom schema option not working #6708

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion server/core/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,27 @@ module.exports = {
}
}
},
// -> Create DB Schema if different than the default 'public'
async createDefaultSchema () {
if (WIKI.config.db.schema && WIKI.config.db.schema !== 'public') {
// 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
async syncSchemas () {
return self.knex.migrate.latest({
tableName: 'migrations',
migrationSource
migrationSource,
schemaName: (WIKI.config.db.schema && WIKI.config.db.schema !== 'public')
? WIKI.config.db.schema : undefined
})
},
// -> Migrate DB Schemas from beta
Expand All @@ -202,6 +218,7 @@ module.exports = {

let initTasksQueue = (WIKI.IS_MASTER) ? [
initTasks.connect,
initTasks.createDefaultSchema,
initTasks.migrateFromBeta,
initTasks.syncSchemas
] : [
Expand Down
2 changes: 2 additions & 0 deletions server/db/beta/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ module.exports = {
const baseMigrationPath = path.join(WIKI.SERVERPATH, (WIKI.config.db.type !== 'sqlite') ? 'db/beta/migrations' : 'db/beta/migrations-sqlite')
await knex.migrate.latest({
tableName: 'migrations',
schemaName: (WIKI.config.db.schema && WIKI.config.db.schema !== 'public')
? WIKI.config.db.schema : undefined,
migrationSource: {
async getMigrations() {
const migrationFiles = await fs.readdir(baseMigrationPath)
Expand Down