fix: JSON fields handling for MariaDB

This commit is contained in:
Nick
2019-02-09 19:10:34 -05:00
parent a8c7710412
commit b1dd54768f
35 changed files with 447 additions and 35 deletions

View File

@@ -19,7 +19,7 @@ module.exports = {
}
if (process.env.dockerdev) {
confPaths.config = path.join(WIKI.ROOTPATH, 'dev/docker/config.yml')
confPaths.config = path.join(WIKI.ROOTPATH, `dev/docker-${process.env.DEVDB}/config.yml`)
}
process.stdout.write(chalk.blue(`Loading configuration from ${confPaths.config}... `))

View File

@@ -84,7 +84,7 @@ module.exports = {
throw new Error('No such locale in local store.')
}
//-> Load dev locale files if present
// -> Load dev locale files if present
if (WIKI.IS_DEBUG) {
try {
const devEntriesRaw = await fs.readFileAsync(path.join(WIKI.SERVERPATH, `locales/${locale}.yml`), 'utf8')

View File

@@ -22,14 +22,15 @@ module.exports = class Authentication extends Model {
properties: {
key: {type: 'string'},
isEnabled: {type: 'boolean'},
config: {type: 'object'},
selfRegistration: {type: 'boolean'},
domainWhitelist: {type: 'object'},
autoEnrollGroups: {type: 'object'}
selfRegistration: {type: 'boolean'}
}
}
}
static get jsonAttributes() {
return ['config', 'domainWhitelist', 'autoEnrollGroups']
}
static async getStrategy(key) {
return WIKI.models.authentication.query().findOne({ key })
}

View File

@@ -21,12 +21,15 @@ module.exports = class Editor extends Model {
properties: {
key: {type: 'string'},
isEnabled: {type: 'boolean'},
config: {type: 'object'}
isEnabled: {type: 'boolean'}
}
}
}
static get jsonAttributes() {
return ['config']
}
static async getEditors() {
return WIKI.models.editors.query()
}

View File

@@ -20,6 +20,10 @@ module.exports = class Group extends Model {
}
}
static get jsonAttributes() {
return ['permissions', 'pageRules']
}
static get relationMappings() {
return {
users: {

View File

@@ -3,7 +3,7 @@ const Model = require('objection').Model
/**
* Locales model
*/
module.exports = class User extends Model {
module.exports = class Locale extends Model {
static get tableName() { return 'locales' }
static get idColumn() { return 'code' }
@@ -14,7 +14,6 @@ module.exports = class User extends Model {
properties: {
code: {type: 'string'},
strings: {type: 'object'},
isRTL: {type: 'boolean', default: false},
name: {type: 'string'},
nativeName: {type: 'string'},
@@ -24,6 +23,10 @@ module.exports = class User extends Model {
}
}
static get jsonAttributes() {
return ['strings']
}
$beforeUpdate() {
this.updatedAt = new Date().toISOString()
}

View File

@@ -22,12 +22,15 @@ module.exports = class Logger extends Model {
properties: {
key: {type: 'string'},
isEnabled: {type: 'boolean'},
level: {type: 'string'},
config: {type: 'object'}
level: {type: 'string'}
}
}
}
static get jsonAttributes() {
return ['config']
}
static async getLoggers() {
return WIKI.models.loggers.query()
}

View File

@@ -22,12 +22,15 @@ module.exports = class Renderer extends Model {
properties: {
key: {type: 'string'},
isEnabled: {type: 'boolean'},
config: {type: 'object'}
isEnabled: {type: 'boolean'}
}
}
}
static get jsonAttributes() {
return ['config']
}
static async getRenderers() {
return WIKI.models.renderers.query()
}

View File

@@ -22,12 +22,15 @@ module.exports = class SearchEngine extends Model {
properties: {
key: {type: 'string'},
isEnabled: {type: 'boolean'},
level: {type: 'string'},
config: {type: 'object'}
level: {type: 'string'}
}
}
}
static get jsonAttributes() {
return ['config']
}
static async getSearchEngines() {
return WIKI.models.searchEngines.query()
}

View File

@@ -13,17 +13,20 @@ module.exports = class Setting extends Model {
static get jsonSchema () {
return {
type: 'object',
required: ['key', 'value'],
required: ['key'],
properties: {
key: {type: 'string'},
value: {type: 'object'},
createdAt: {type: 'string'},
updatedAt: {type: 'string'}
}
}
}
static get jsonAttributes() {
return ['value']
}
$beforeUpdate() {
this.updatedAt = new Date().toISOString()
}

View File

@@ -24,12 +24,15 @@ module.exports = class Storage extends Model {
properties: {
key: {type: 'string'},
isEnabled: {type: 'boolean'},
mode: {type: 'string'},
config: {type: 'object'}
mode: {type: 'string'}
}
}
}
static get jsonAttributes() {
return ['config']
}
static async getTargets() {
return WIKI.models.storage.query()
}