fix: mssql initial migration crash
This commit is contained in:
@@ -34,6 +34,7 @@ module.exports = {
|
||||
case 'postgres':
|
||||
dbClient = 'pg'
|
||||
break
|
||||
case 'mariadb':
|
||||
case 'mysql':
|
||||
dbClient = 'mysql2'
|
||||
break
|
||||
@@ -52,6 +53,7 @@ module.exports = {
|
||||
this.knex = Knex({
|
||||
client: dbClient,
|
||||
useNullAsDefault: true,
|
||||
asyncStackTraces: WIKI.IS_DEBUG,
|
||||
connection: dbConfig,
|
||||
pool: {
|
||||
async afterCreate(conn, done) {
|
||||
|
@@ -25,8 +25,7 @@ exports.up = knex => {
|
||||
})
|
||||
// AUTHENTICATION ----------------------
|
||||
.createTable('authentication', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.string('key').notNullable().primary()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.json('config').notNullable()
|
||||
table.boolean('selfRegistration').notNullable().defaultTo(false)
|
||||
@@ -42,8 +41,7 @@ exports.up = knex => {
|
||||
})
|
||||
// EDITORS -----------------------------
|
||||
.createTable('editors', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.string('key').notNullable().primary()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.json('config').notNullable()
|
||||
})
|
||||
@@ -56,8 +54,7 @@ exports.up = knex => {
|
||||
})
|
||||
// LOCALES -----------------------------
|
||||
.createTable('locales', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('code', 2).notNullable().unique()
|
||||
table.string('code', 2).notNullable().primary()
|
||||
table.json('strings')
|
||||
table.boolean('isRTL').notNullable().defaultTo(false)
|
||||
table.string('name').notNullable()
|
||||
@@ -67,8 +64,7 @@ exports.up = knex => {
|
||||
})
|
||||
// LOGGING ----------------------------
|
||||
.createTable('loggers', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.string('key').notNullable().primary()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.string('level').notNullable().defaultTo('warn')
|
||||
table.json('config')
|
||||
@@ -106,29 +102,25 @@ exports.up = knex => {
|
||||
})
|
||||
// RENDERERS ---------------------------
|
||||
.createTable('renderers', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.string('key').notNullable().primary()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.json('config')
|
||||
})
|
||||
// SEARCH ------------------------------
|
||||
.createTable('searchEngines', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.string('key').notNullable().primary()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.json('config')
|
||||
})
|
||||
// SETTINGS ----------------------------
|
||||
.createTable('settings', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.string('key').notNullable().primary()
|
||||
table.json('value')
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// STORAGE -----------------------------
|
||||
.createTable('storage', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.string('key').notNullable().primary()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.string('mode', ['sync', 'push', 'pull']).notNullable().defaultTo('push')
|
||||
table.json('config')
|
||||
|
@@ -8,7 +8,8 @@ const path = require('path')
|
||||
/* global WIKI */
|
||||
|
||||
const dbTypes = {
|
||||
mysql: 'MySQL / MariaDB',
|
||||
mysql: 'MySQL',
|
||||
mariadb: 'MariaDB',
|
||||
postgres: 'PostgreSQL',
|
||||
sqlite: 'SQLite',
|
||||
mssql: 'MS SQL Server'
|
||||
@@ -35,11 +36,33 @@ module.exports = {
|
||||
dbType() {
|
||||
return _.get(dbTypes, WIKI.config.db.type, 'Unknown DB')
|
||||
},
|
||||
dbVersion() {
|
||||
return _.get(WIKI.models, 'knex.client.version', 'Unknown version')
|
||||
async dbVersion() {
|
||||
let version = 'Unknown Version'
|
||||
switch (WIKI.config.db.type) {
|
||||
case 'mariadb':
|
||||
case 'mysql':
|
||||
const resultMYSQL = await WIKI.models.knex.raw('SELECT VERSION() as version;')
|
||||
version = _.get(resultMYSQL, '[0][0].version', 'Unknown Version')
|
||||
break
|
||||
case 'mssql':
|
||||
const resultMSSQL = await WIKI.models.knex.raw('SELECT @@VERSION as version;')
|
||||
version = _.get(resultMSSQL, '[0].version', 'Unknown Version')
|
||||
break
|
||||
case 'postgres':
|
||||
version = _.get(WIKI.models, 'knex.client.version', 'Unknown Version')
|
||||
break
|
||||
case 'sqlite':
|
||||
version = _.get(WIKI.models, 'knex.client.driver.VERSION', 'Unknown Version')
|
||||
break
|
||||
}
|
||||
return version
|
||||
},
|
||||
dbHost() {
|
||||
return WIKI.config.db.host
|
||||
if (WIKI.config.db.type === 'sqlite') {
|
||||
return WIKI.config.db.storage
|
||||
} else {
|
||||
return WIKI.config.db.host
|
||||
}
|
||||
},
|
||||
latestVersion() {
|
||||
return '2.0.0' // TODO
|
||||
|
@@ -12,6 +12,7 @@ const commonHelper = require('../helpers/common')
|
||||
*/
|
||||
module.exports = class Authentication extends Model {
|
||||
static get tableName() { return 'authentication' }
|
||||
static get idColumn() { return 'key' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
@@ -19,7 +20,6 @@ module.exports = class Authentication extends Model {
|
||||
required: ['key', 'isEnabled'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
key: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'},
|
||||
config: {type: 'object'},
|
||||
|
@@ -12,6 +12,7 @@ const commonHelper = require('../helpers/common')
|
||||
*/
|
||||
module.exports = class Editor extends Model {
|
||||
static get tableName() { return 'editors' }
|
||||
static get idColumn() { return 'key' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
@@ -19,7 +20,6 @@ module.exports = class Editor extends Model {
|
||||
required: ['key', 'isEnabled'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
key: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'},
|
||||
config: {type: 'object'}
|
||||
|
@@ -5,6 +5,7 @@ const Model = require('objection').Model
|
||||
*/
|
||||
module.exports = class User extends Model {
|
||||
static get tableName() { return 'locales' }
|
||||
static get idColumn() { return 'code' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
@@ -12,7 +13,6 @@ module.exports = class User extends Model {
|
||||
required: ['code', 'name'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
code: {type: 'string'},
|
||||
strings: {type: 'object'},
|
||||
isRTL: {type: 'boolean', default: false},
|
||||
|
@@ -12,6 +12,7 @@ const commonHelper = require('../helpers/common')
|
||||
*/
|
||||
module.exports = class Logger extends Model {
|
||||
static get tableName() { return 'loggers' }
|
||||
static get idColumn() { return 'key' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
@@ -19,7 +20,6 @@ module.exports = class Logger extends Model {
|
||||
required: ['key', 'isEnabled'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
key: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'},
|
||||
level: {type: 'string'},
|
||||
|
@@ -12,6 +12,7 @@ const commonHelper = require('../helpers/common')
|
||||
*/
|
||||
module.exports = class Renderer extends Model {
|
||||
static get tableName() { return 'renderers' }
|
||||
static get idColumn() { return 'key' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
@@ -19,7 +20,6 @@ module.exports = class Renderer extends Model {
|
||||
required: ['key', 'isEnabled'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
key: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'},
|
||||
config: {type: 'object'}
|
||||
|
@@ -12,6 +12,7 @@ const commonHelper = require('../helpers/common')
|
||||
*/
|
||||
module.exports = class SearchEngine extends Model {
|
||||
static get tableName() { return 'searchEngines' }
|
||||
static get idColumn() { return 'key' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
@@ -19,7 +20,6 @@ module.exports = class SearchEngine extends Model {
|
||||
required: ['key', 'isEnabled'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
key: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'},
|
||||
level: {type: 'string'},
|
||||
|
@@ -8,6 +8,7 @@ const _ = require('lodash')
|
||||
*/
|
||||
module.exports = class Setting extends Model {
|
||||
static get tableName() { return 'settings' }
|
||||
static get idColumn() { return 'key' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
@@ -15,7 +16,6 @@ module.exports = class Setting extends Model {
|
||||
required: ['key', 'value'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
key: {type: 'string'},
|
||||
value: {type: 'object'},
|
||||
createdAt: {type: 'string'},
|
||||
|
@@ -12,6 +12,7 @@ const commonHelper = require('../helpers/common')
|
||||
*/
|
||||
module.exports = class Storage extends Model {
|
||||
static get tableName() { return 'storage' }
|
||||
static get idColumn() { return 'key' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
@@ -19,7 +20,6 @@ module.exports = class Storage extends Model {
|
||||
required: ['key', 'isEnabled'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
key: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'},
|
||||
mode: {type: 'string'},
|
||||
|
Reference in New Issue
Block a user