Browse Source

fix: mysql + sqlite incompatible queries

pull/621/head
Nicolas Giard 6 years ago
parent
commit
96f4e89020
12 changed files with 500 additions and 267 deletions
  1. 3
      .gitignore
  2. 2
      client/components/setup.vue
  3. 1
      client/scss/app.scss
  4. 33
      client/scss/base/icons.scss
  5. 2
      config.sample.yml
  6. 38
      package.json
  7. 8
      server/core/db.js
  8. 16
      server/db/migrations/2.0.0.js
  9. 10
      server/models/authentication.js
  10. 10
      server/models/storage.js
  11. 2
      server/setup.js
  12. 642
      yarn.lock

3
.gitignore

@ -29,6 +29,7 @@ npm-debug.log*
/repo
/data
/uploads
*.sqlite
# IDE exclude
.idea
@ -38,4 +39,4 @@ npm-debug.log*
test-results/
# Localization Resources
/server/locales/**/*.yml
/server/locales/**/*.yml

2
client/components/setup.vue

@ -48,7 +48,7 @@
br
| Should you have any question or would like to report something that doesn't look right, feel free to create a new issue on the #[a(href='https://github.com/Requarks/wiki/issues') GitHub project].
.body-1.pt-3
svg.icons.is-18.is-outlined.has-right-pad.is-text: use(xlink:href='#nc-cd-reader')
v-icon.mr-2 system_update
span You are about to install Wiki.js #[strong {{wikiVersion}}].
v-divider.mt-3
v-form

1
client/scss/app.scss

@ -1,6 +1,7 @@
@import "global";
@import "base/base";
@import "base/icons";
@import "../libs/animate/animate";

33
client/scss/base/icons.scss

@ -0,0 +1,33 @@
.icons {
display: inline-block;
color: mc('grey', '800');
&.is-text {
display: inline-block;
width: 1em;
height: 1em;
vertical-align: middle;
position: relative;
top: -0.0625em;
stroke: none;
fill: none;
}
@each $size in 16,18,20,24,32,48,64,96,128 {
&.is-#{$size} {
width: #{$size}px;
height: #{$size}px;
}
}
&.has-right-pad {
margin-right: .5rem;
}
&.is-outlined {
stroke-width: 2px;
use {
fill: inherit;
stroke: mc('grey', '800');
}
}
}
.material-design-icon {
display: inline-flex;
}

2
config.sample.yml

@ -23,7 +23,7 @@ paths:
# ---------------------------------------------------------------------
# Supported Database Engines:
# - postgres = PostgreSQL 9.5 or later
# - mysql = MySQL 8.0 / MariaDB 10.2.7 or later
# - mysql = MySQL 5.7.8 / MariaDB 10.2.7 or later
# - mssql = MS SQL Server 2012 or later
# - sqlite = SQLite 3.9 or later

38
package.json

@ -37,15 +37,15 @@
"node": ">=8.11"
},
"dependencies": {
"apollo-server": "2.0.0",
"apollo-server-express": "2.0.0",
"apollo-server": "2.0.2",
"apollo-server-express": "2.0.2",
"auto-load": "3.0.0",
"axios": "0.18.0",
"bcryptjs-then": "1.0.1",
"bluebird": "3.5.1",
"body-parser": "1.18.3",
"bugsnag": "2.4.3",
"bull": "3.4.4",
"bull": "3.4.7",
"chalk": "2.4.1",
"cheerio": "1.0.0-rc.2",
"child-process-promise": "2.2.1",
@ -62,20 +62,20 @@
"express-brute": "1.0.1",
"express-brute-redis": "0.0.1",
"express-session": "1.15.6",
"file-type": "8.1.0",
"file-type": "9.0.0",
"filesize.js": "1.0.2",
"follow-redirects": "1.5.2",
"follow-redirects": "1.5.5",
"fs-extra": "7.0.0",
"getos": "3.1.0",
"graphql": "0.13.2",
"graphql-list-fields": "2.0.2",
"graphql-tools": "3.1.1",
"i18next": "11.5.0",
"i18next": "11.6.0",
"i18next-express-middleware": "1.2.1",
"i18next-localstorage-cache": "1.1.1",
"i18next-node-fs-backend": "1.2.1",
"image-size": "0.6.3",
"ioredis": "3.2.2",
"ioredis": "4.0.0",
"js-yaml": "3.12.0",
"jsonwebtoken": "8.3.0",
"klaw": "3.0.0",
@ -99,7 +99,7 @@
"mime-types": "2.1.19",
"moment": "2.22.2",
"moment-timezone": "0.5.21",
"mongodb": "3.1.1",
"mongodb": "3.1.3",
"mssql": "4.1.0",
"multer": "1.3.1",
"mysql2": "1.6.1",
@ -133,7 +133,7 @@
"raven": "2.6.3",
"read-chunk": "2.1.0",
"remove-markdown": "0.3.0",
"request": "2.87.0",
"request": "2.88.0",
"request-promise": "4.2.2",
"scim-query-filter-parser": "1.1.0",
"semver": "5.5.0",
@ -147,16 +147,16 @@
},
"devDependencies": {
"@panter/vue-i18next": "0.12.0",
"@vue/cli": "3.0.0-rc.11",
"apollo-cache-inmemory": "1.2.6",
"apollo-client": "2.3.7",
"@vue/cli": "3.0.0",
"apollo-cache-inmemory": "1.2.7",
"apollo-client": "2.3.8",
"apollo-fetch": "0.7.0",
"apollo-link": "1.2.2",
"apollo-link-batch-http": "1.2.2",
"apollo-link-error": "1.1.0",
"apollo-link-http": "1.5.4",
"apollo-link-persisted-queries": "0.2.1",
"autoprefixer": "9.1.0",
"autoprefixer": "9.1.1",
"babel-cli": "6.26.0",
"babel-core": "6.26.3",
"babel-eslint": "8.2.6",
@ -180,7 +180,7 @@
"eslint": "5.3.0",
"eslint-config-requarks": "1.0.7",
"eslint-config-standard": "11.0.0",
"eslint-plugin-import": "2.13.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-node": "7.0.1",
"eslint-plugin-promise": "3.8.0",
"eslint-plugin-standard": "3.1.0",
@ -195,19 +195,19 @@
"html-webpack-pug-plugin": "0.3.0",
"i18next-xhr-backend": "1.5.1",
"ignore-loader": "0.1.2",
"jest": "23.4.2",
"jest": "23.5.0",
"jest-junit": "5.1.0",
"js-cookie": "2.2.0",
"lodash-webpack-plugin": "0.11.5",
"mini-css-extract-plugin": "0.4.1",
"node-sass": "4.9.2",
"node-sass": "4.9.3",
"offline-plugin": "5.0.5",
"optimize-css-assets-webpack-plugin": "5.0.0",
"postcss-cssnext": "3.1.0",
"postcss-flexbugs-fixes": "4.1.0",
"postcss-flexibility": "2.0.0",
"postcss-import": "12.0.0",
"postcss-loader": "2.1.6",
"postcss-loader": "3.0.0",
"postcss-preset-env": "5.3.0",
"postcss-selector-parser": "5.0.0-rc.3",
"pug-lint": "2.5.0",
@ -224,7 +224,7 @@
"stylus": "0.54.5",
"stylus-loader": "3.0.2",
"twemoji-awesome": "1.0.6",
"url-loader": "1.0.1",
"url-loader": "1.1.0",
"vee-validate": "2.1.0-beta.7",
"velocity-animate": "1.5.2",
"vue": "2.5.17",
@ -243,7 +243,7 @@
"vue-tour": "1.0.1",
"vue-tree-navigation": "3.0.1",
"vuedraggable": "2.16.0",
"vuetify": "1.1.10",
"vuetify": "1.1.12",
"vuex": "3.0.1",
"vuex-pathify": "1.1.3",
"vuex-persistedstate": "2.5.4",

8
server/core/db.js

@ -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')

16
server/db/migrations/2.0.0.js

@ -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 => {

10
server/models/authentication.js

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

10
server/models/storage.js

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

2
server/setup.js

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

642
yarn.lock
File diff suppressed because it is too large
View File

Loading…
Cancel
Save