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

@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fixed error page metadata title warning - Fixed error page metadata title warning
- Fixed telemetry - Fixed telemetry
- Await page render job to complete before resolving - Await page render job to complete before resolving
- Fixed JSON fields for MariaDB
### Changed ### Changed
- Moved Insert Media button in Markdown editor - Moved Insert Media button in Markdown editor

View File

@ -1,4 +1,5 @@
SHELL := /bin/bash SHELL := /bin/bash
DEVDB := postgres
start: ## Start Wiki.js in production mode start: ## Start Wiki.js in production mode
node wiki start node wiki start
@ -23,27 +24,30 @@ test: ## Run code linting tests
pug-lint server/views && jest pug-lint server/views && jest
docker-dev-up: ## Run dockerized dev environment docker-dev-up: ## Run dockerized dev environment
docker-compose -f ./dev/docker/docker-compose.yml -p wiki --project-directory . up -d docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . up -d
docker-compose -f ./dev/docker/docker-compose.yml -p wiki --project-directory . exec wiki yarn dev docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . exec wiki yarn dev
docker-dev-down: ## Shutdown dockerized dev environment docker-dev-down: ## Shutdown dockerized dev environment
docker-compose -f ./dev/docker/docker-compose.yml -p wiki --project-directory . down docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . down
docker-dev-rebuild: ## Rebuild dockerized dev image docker-dev-rebuild: ## Rebuild dockerized dev image
rm -rf ./node_modules rm -rf ./node_modules
docker-compose -f ./dev/docker/docker-compose.yml -p wiki --project-directory . build --no-cache --force-rm docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . build --no-cache --force-rm
docker-dev-clean: ## Clean DB, redis and data folders docker-dev-clean: ## Clean DB, redis and data folders
rm -rf ./data rm -rf ./data
docker-compose -f ./dev/docker/docker-compose.yml -p wiki --project-directory . exec db psql --dbname=wiki --username=wikijs --command='DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public' [[ "${DEVDB}" == "postgres" ]] && docker-compose -f ./dev/docker-postgres/docker-compose.yml -p wiki --project-directory . exec db psql --dbname=wiki --username=wikijs --command='DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public' || true
docker-compose -f ./dev/docker/docker-compose.yml -p wiki --project-directory . exec redis redis-cli flushall [[ "${DEVDB}" == "mysql" || "${DEVDB}" == "mariadb" ]] && docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . exec db mysql -uroot -p'wikijsrocks' -e 'DROP SCHEMA IF EXISTS wiki; CREATE SCHEMA wiki;' || true
## [[ "${DEVDB}" = "mssql" ]] && docker-compose -f ./dev/docker-mssql/docker-compose.yml -p wiki --project-directory . exec db ls
[[ "${DEVDB}" == "sqlite" ]] && docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . exec wiki rm -rf /wiki/db.sqlite || true
docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . exec redis redis-cli flushall
docker-dev-bash: ## Rebuild dockerized dev image docker-dev-bash: ## Rebuild dockerized dev image
docker-compose -f ./dev/docker/docker-compose.yml -p wiki --project-directory . exec wiki bash docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . exec wiki bash
docker-build: ## Run assets generation build in docker docker-build: ## Run assets generation build in docker
docker-compose -f ./dev/docker/docker-compose.yml -p wiki --project-directory . run wiki yarn build docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . run wiki yarn build
docker-compose -f ./dev/docker/docker-compose.yml -p wiki --project-directory . down docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . down
help: ## Display help help: ## Display help
@echo '' @echo ''

View File

@ -29,7 +29,7 @@ FROM node:10.15-alpine
LABEL maintainer="requarks.io" LABEL maintainer="requarks.io"
RUN apk update && \ RUN apk update && \
apk add bash curl git openssh gnupg supervisor --no-cache && \ apk add bash curl git openssh gnupg sqlite --no-cache && \
rm -rf /var/cache/apk/* && \ rm -rf /var/cache/apk/* && \
mkdir -p /wiki && \ mkdir -p /wiki && \
mkdir -p /logs mkdir -p /logs

View File

@ -0,0 +1,21 @@
# -- DEV DOCKERFILE --
# -- DO NOT USE IN PRODUCTION! --
FROM node:10-alpine
LABEL maintainer "requarks.io"
RUN apk update && \
apk add bash curl git python make g++ nano openssh gnupg --no-cache && \
mkdir -p /wiki
WORKDIR /wiki
COPY package.json .
RUN yarn --silent
COPY ./dev/docker-mariadb/init.sh ./init.sh
ENV dockerdev 1
ENV DEVDB mariadb
EXPOSE 3000
CMD ["tail", "-f", "/dev/null"]

View File

@ -0,0 +1,14 @@
port: 3000
bindIP: 0.0.0.0
db:
type: mariadb
host: db
port: 3306
user: wikijs
pass: wikijsrocks
db: wiki
redis:
host: redis
port: 6379
db: 0
logLevel: info

View File

@ -0,0 +1,61 @@
# -- DEV DOCKER-COMPOSE --
# -- DO NOT USE IN PRODUCTION! --
version: "3"
services:
redis:
image: redis:4-alpine
ports:
- "16379:6379"
logging:
driver: "none"
networks:
- wikinet
db:
image: mariadb:10.3
environment:
MYSQL_DATABASE: wiki
MYSQL_PASSWORD: wikijsrocks
MYSQL_USER: wikijs
MYSQL_ROOT_PASSWORD: wikijsrocks
logging:
driver: "none"
volumes:
- db-data:/var/lib/mysql
networks:
- wikinet
ports:
- "13306:3306"
adminer:
image: adminer:latest
logging:
driver: "none"
networks:
- wikinet
ports:
- "3001:8080"
wiki:
build:
context: .
dockerfile: dev/docker-mariadb/Dockerfile
depends_on:
- db
- redis
networks:
- wikinet
ports:
- "3000:3000"
volumes:
- .:/wiki
- /wiki/node_modules
command: ["sh", "./dev/docker-mariadb/init.sh"]
networks:
wikinet:
volumes:
db-data:

View File

@ -0,0 +1,7 @@
#!/bin/sh
echo "Waiting for redis and mariadb to start up..."
bash ./dev/docker-common/wait.sh redis:6379
bash ./dev/docker-common/wait.sh db:3306
echo "=== READY ==="
tail -f /dev/null

View File

@ -11,9 +11,10 @@ RUN apk update && \
WORKDIR /wiki WORKDIR /wiki
COPY package.json . COPY package.json .
RUN yarn --silent RUN yarn --silent
COPY ./dev/docker/init.sh ./init.sh COPY ./dev/docker-mssql/init.sh ./init.sh
ENV dockerdev 1 ENV dockerdev 1
ENV DEVDB mssql
EXPOSE 3000 EXPOSE 3000

View File

@ -0,0 +1,14 @@
port: 3000
bindIP: 0.0.0.0
db:
type: mssql
host: db
port: 1433
user: SA
pass: W1kiJSR0cks!
db: wiki
redis:
host: redis
port: 6379
db: 0
logLevel: info

View File

@ -0,0 +1,60 @@
# -- DEV DOCKER-COMPOSE --
# -- DO NOT USE IN PRODUCTION! --
version: "3"
services:
redis:
image: redis:4-alpine
ports:
- "16379:6379"
logging:
driver: "none"
networks:
- wikinet
db:
image: mcr.microsoft.com/mssql/server:2017-latest
environment:
ACCEPT_EULA: 'Y'
MSSQL_PID: Developer
SA_PASSWORD: W1kiJSR0cks!
logging:
driver: "none"
volumes:
- db-data:/var/opt/mssql
networks:
- wikinet
ports:
- "11433:1433"
adminer:
image: adminer:latest
logging:
driver: "none"
networks:
- wikinet
ports:
- "3001:8080"
wiki:
build:
context: .
dockerfile: dev/docker-mssql/Dockerfile
depends_on:
- db
- redis
networks:
- wikinet
ports:
- "3000:3000"
volumes:
- .:/wiki
- /wiki/node_modules
command: ["sh", "./dev/docker-mssql/init.sh"]
networks:
wikinet:
volumes:
db-data:

7
dev/docker-mssql/init.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/sh
echo "Waiting for redis and mssql to start up..."
bash ./dev/docker-common/wait.sh redis:6379
bash ./dev/docker-common/wait.sh db:1433
echo "=== READY ==="
tail -f /dev/null

View File

@ -0,0 +1,21 @@
# -- DEV DOCKERFILE --
# -- DO NOT USE IN PRODUCTION! --
FROM node:10-alpine
LABEL maintainer "requarks.io"
RUN apk update && \
apk add bash curl git python make g++ nano openssh gnupg --no-cache && \
mkdir -p /wiki
WORKDIR /wiki
COPY package.json .
RUN yarn --silent
COPY ./dev/docker-mysql/init.sh ./init.sh
ENV dockerdev 1
ENV DEVDB mysql
EXPOSE 3000
CMD ["tail", "-f", "/dev/null"]

View File

@ -0,0 +1,14 @@
port: 3000
bindIP: 0.0.0.0
db:
type: mysql
host: db
port: 3306
user: wikijs
pass: wikijsrocks
db: wiki
redis:
host: redis
port: 6379
db: 0
logLevel: info

View File

@ -0,0 +1,61 @@
# -- DEV DOCKER-COMPOSE --
# -- DO NOT USE IN PRODUCTION! --
version: "3"
services:
redis:
image: redis:4-alpine
ports:
- "16379:6379"
logging:
driver: "none"
networks:
- wikinet
db:
image: mysql:5.7
environment:
MYSQL_DATABASE: wiki
MYSQL_PASSWORD: wikijsrocks
MYSQL_USER: wikijs
MYSQL_ROOT_PASSWORD: wikijsrocks
logging:
driver: "none"
volumes:
- db-data:/var/lib/mysql
networks:
- wikinet
ports:
- "13306:3306"
adminer:
image: adminer:latest
logging:
driver: "none"
networks:
- wikinet
ports:
- "3001:8080"
wiki:
build:
context: .
dockerfile: dev/docker-mysql/Dockerfile
depends_on:
- db
- redis
networks:
- wikinet
ports:
- "3000:3000"
volumes:
- .:/wiki
- /wiki/node_modules
command: ["sh", "./dev/docker-mysql/init.sh"]
networks:
wikinet:
volumes:
db-data:

7
dev/docker-mysql/init.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/sh
echo "Waiting for redis and mysql to start up..."
bash ./dev/docker-common/wait.sh redis:6379
bash ./dev/docker-common/wait.sh db:3306
echo "=== READY ==="
tail -f /dev/null

View File

@ -0,0 +1,21 @@
# -- DEV DOCKERFILE --
# -- DO NOT USE IN PRODUCTION! --
FROM node:10-alpine
LABEL maintainer "requarks.io"
RUN apk update && \
apk add bash curl git python make g++ nano openssh gnupg --no-cache && \
mkdir -p /wiki
WORKDIR /wiki
COPY package.json .
RUN yarn --silent
COPY ./dev/docker-postgres/init.sh ./init.sh
ENV dockerdev 1
ENV DEVDB postgres
EXPOSE 3000
CMD ["tail", "-f", "/dev/null"]

View File

@ -40,7 +40,7 @@ services:
wiki: wiki:
build: build:
context: . context: .
dockerfile: dev/docker/Dockerfile dockerfile: dev/docker-postgres/Dockerfile
depends_on: depends_on:
- db - db
- redis - redis
@ -51,7 +51,7 @@ services:
volumes: volumes:
- .:/wiki - .:/wiki
- /wiki/node_modules - /wiki/node_modules
command: ["sh", "./dev/docker/init.sh"] command: ["sh", "./dev/docker-postgres/init.sh"]
networks: networks:
wikinet: wikinet:

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
echo "Waiting for redis and postgres to start up..." echo "Waiting for redis and postgres to start up..."
bash ./dev/docker/wait.sh redis:6379 bash ./dev/docker-common/wait.sh redis:6379
bash ./dev/docker/wait.sh db:5432 bash ./dev/docker-common/wait.sh db:5432
echo "=== READY ===" echo "=== READY ==="
tail -f /dev/null tail -f /dev/null

View File

@ -0,0 +1,21 @@
# -- DEV DOCKERFILE --
# -- DO NOT USE IN PRODUCTION! --
FROM node:10-alpine
LABEL maintainer "requarks.io"
RUN apk update && \
apk add bash curl git python make g++ nano openssh gnupg sqlite --no-cache && \
mkdir -p /wiki
WORKDIR /wiki
COPY package.json .
RUN yarn --silent
COPY ./dev/docker-sqlite/init.sh ./init.sh
ENV dockerdev 1
ENV DEVDB sqlite
EXPOSE 3000
CMD ["tail", "-f", "/dev/null"]

View File

@ -0,0 +1,10 @@
port: 3000
bindIP: 0.0.0.0
db:
type: sqlite
storage: /wiki/db.sqlite
redis:
host: redis
port: 6379
db: 0
logLevel: info

View File

@ -0,0 +1,35 @@
# -- DEV DOCKER-COMPOSE --
# -- DO NOT USE IN PRODUCTION! --
version: "3"
services:
redis:
image: redis:4-alpine
ports:
- "16379:6379"
logging:
driver: "none"
networks:
- wikinet
wiki:
build:
context: .
dockerfile: dev/docker-sqlite/Dockerfile
depends_on:
- redis
networks:
- wikinet
ports:
- "3000:3000"
volumes:
- .:/wiki
- /wiki/node_modules
command: ["sh", "./dev/docker-sqlite/init.sh"]
networks:
wikinet:
volumes:
db-data:

View File

@ -0,0 +1,6 @@
#!/bin/sh
echo "Waiting for redis to start up..."
bash ./dev/docker-common/wait.sh redis:6379
echo "=== READY ==="
tail -f /dev/null

View File

@ -19,7 +19,7 @@ module.exports = {
} }
if (process.env.dockerdev) { 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}... `)) process.stdout.write(chalk.blue(`Loading configuration from ${confPaths.config}... `))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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