fix: mysql + sqlite incompatible queries
This commit is contained in:
@@ -8,7 +8,7 @@ const Objection = require('objection')
|
||||
/* global WIKI */
|
||||
|
||||
/**
|
||||
* PostgreSQL DB module
|
||||
* ORM DB module
|
||||
*/
|
||||
module.exports = {
|
||||
Objection,
|
||||
@@ -22,13 +22,12 @@ module.exports = {
|
||||
let self = this
|
||||
|
||||
let dbClient = null
|
||||
const dbConfig = (!_.isEmpty(process.env.WIKI_DB_CONNSTR)) ? process.env.WIKI_DB_CONNSTR : {
|
||||
let dbConfig = (!_.isEmpty(process.env.WIKI_DB_CONNSTR)) ? process.env.WIKI_DB_CONNSTR : {
|
||||
host: WIKI.config.db.host,
|
||||
user: WIKI.config.db.user,
|
||||
password: WIKI.config.db.pass,
|
||||
database: WIKI.config.db.db,
|
||||
port: WIKI.config.db.port,
|
||||
filename: WIKI.config.db.storage
|
||||
port: WIKI.config.db.port
|
||||
}
|
||||
|
||||
switch (WIKI.config.db.type) {
|
||||
@@ -43,6 +42,7 @@ module.exports = {
|
||||
break
|
||||
case 'sqlite':
|
||||
dbClient = 'sqlite3'
|
||||
dbConfig = { filename: WIKI.config.db.storage }
|
||||
break
|
||||
default:
|
||||
WIKI.logger.error('Invalid DB Type')
|
||||
|
@@ -12,7 +12,7 @@ exports.up = knex => {
|
||||
table.enum('kind', ['binary', 'image']).notNullable().defaultTo('binary')
|
||||
table.string('mime').notNullable().defaultTo('application/octet-stream')
|
||||
table.integer('fileSize').unsigned().comment('In kilobytes')
|
||||
table.jsonb('metadata')
|
||||
table.json('metadata')
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
@@ -28,10 +28,10 @@ exports.up = knex => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.jsonb('config').notNullable()
|
||||
table.json('config').notNullable()
|
||||
table.boolean('selfRegistration').notNullable().defaultTo(false)
|
||||
table.jsonb('domainWhitelist').notNullable()
|
||||
table.jsonb('autoEnrollGroups').notNullable()
|
||||
table.json('domainWhitelist').notNullable()
|
||||
table.json('autoEnrollGroups').notNullable()
|
||||
})
|
||||
// COMMENTS ----------------------------
|
||||
.createTable('comments', table => {
|
||||
@@ -45,7 +45,7 @@ exports.up = knex => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.jsonb('config').notNullable()
|
||||
table.json('config').notNullable()
|
||||
})
|
||||
// GROUPS ------------------------------
|
||||
.createTable('groups', table => {
|
||||
@@ -58,7 +58,7 @@ exports.up = knex => {
|
||||
.createTable('locales', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('code', 2).notNullable().unique()
|
||||
table.jsonb('strings')
|
||||
table.json('strings')
|
||||
table.boolean('isRTL').notNullable().defaultTo(false)
|
||||
table.string('name').notNullable()
|
||||
table.string('nativeName').notNullable()
|
||||
@@ -99,7 +99,7 @@ exports.up = knex => {
|
||||
.createTable('settings', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.jsonb('value')
|
||||
table.json('value')
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// STORAGE -----------------------------
|
||||
@@ -108,7 +108,7 @@ exports.up = knex => {
|
||||
table.string('key').notNullable().unique()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.enum('mode', ['sync', 'push', 'pull']).notNullable().defaultTo('push')
|
||||
table.jsonb('config')
|
||||
table.json('config')
|
||||
})
|
||||
// TAGS --------------------------------
|
||||
.createTable('tags', table => {
|
||||
|
@@ -40,6 +40,7 @@ module.exports = class Authentication extends Model {
|
||||
}
|
||||
|
||||
static async refreshStrategiesFromDisk() {
|
||||
let trx
|
||||
try {
|
||||
const dbStrategies = await WIKI.models.authentication.query()
|
||||
|
||||
@@ -82,7 +83,11 @@ module.exports = class Authentication extends Model {
|
||||
}
|
||||
}
|
||||
if (newStrategies.length > 0) {
|
||||
await WIKI.models.authentication.query().insert(newStrategies)
|
||||
trx = await WIKI.models.Objection.transaction.start(WIKI.models.knex)
|
||||
for (let strategy of newStrategies) {
|
||||
await WIKI.models.authentication.query(trx).insert(strategy)
|
||||
}
|
||||
await trx.commit()
|
||||
WIKI.logger.info(`Loaded ${newStrategies.length} new authentication strategies: [ OK ]`)
|
||||
} else {
|
||||
WIKI.logger.info(`No new authentication strategies found: [ SKIPPED ]`)
|
||||
@@ -90,6 +95,9 @@ module.exports = class Authentication extends Model {
|
||||
} catch (err) {
|
||||
WIKI.logger.error(`Failed to scan or load new authentication providers: [ FAILED ]`)
|
||||
WIKI.logger.error(err)
|
||||
if (trx) {
|
||||
trx.rollback()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ module.exports = class Storage extends Model {
|
||||
}
|
||||
|
||||
static async refreshTargetsFromDisk() {
|
||||
let trx
|
||||
try {
|
||||
const dbTargets = await WIKI.models.storage.query()
|
||||
|
||||
@@ -74,7 +75,11 @@ module.exports = class Storage extends Model {
|
||||
}
|
||||
}
|
||||
if (newTargets.length > 0) {
|
||||
await WIKI.models.storage.query().insert(newTargets)
|
||||
trx = await WIKI.models.Objection.transaction.start(WIKI.models.knex)
|
||||
for (let target of newTargets) {
|
||||
await WIKI.models.storage.query(trx).insert(target)
|
||||
}
|
||||
await trx.commit()
|
||||
WIKI.logger.info(`Loaded ${newTargets.length} new storage targets: [ OK ]`)
|
||||
} else {
|
||||
WIKI.logger.info(`No new storage targets found: [ SKIPPED ]`)
|
||||
@@ -82,6 +87,9 @@ module.exports = class Storage extends Model {
|
||||
} catch (err) {
|
||||
WIKI.logger.error(`Failed to scan or load new storage providers: [ FAILED ]`)
|
||||
WIKI.logger.error(err)
|
||||
if (trx) {
|
||||
trx.rollback()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -70,7 +70,7 @@ module.exports = () => {
|
||||
|
||||
app.get('*', async (req, res) => {
|
||||
let packageObj = await fs.readJson(path.join(WIKI.ROOTPATH, 'package.json'))
|
||||
res.render('main/setup', {
|
||||
res.render('setup', {
|
||||
packageObj,
|
||||
telemetryClientID: WIKI.telemetry.cid
|
||||
})
|
||||
|
Reference in New Issue
Block a user