fix: mysql + sqlite incompatible queries

This commit is contained in:
Nicolas Giard
2018-08-15 21:57:28 -04:00
parent 65f1611741
commit 96f4e89020
12 changed files with 500 additions and 267 deletions

View File

@@ -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()
}
}
}
}