Browse Source

fix: JSON fields handling for MariaDB

pull/760/head
Nick 5 years ago
parent
commit
b1dd54768f
35 changed files with 447 additions and 35 deletions
  1. 1
      CHANGELOG.md
  2. 22
      Makefile
  3. 2
      dev/build/Dockerfile
  4. 0
      dev/docker-common/wait.sh
  5. 21
      dev/docker-mariadb/Dockerfile
  6. 14
      dev/docker-mariadb/config.yml
  7. 61
      dev/docker-mariadb/docker-compose.yml
  8. 7
      dev/docker-mariadb/init.sh
  9. 3
      dev/docker-mssql/Dockerfile
  10. 14
      dev/docker-mssql/config.yml
  11. 60
      dev/docker-mssql/docker-compose.yml
  12. 7
      dev/docker-mssql/init.sh
  13. 21
      dev/docker-mysql/Dockerfile
  14. 14
      dev/docker-mysql/config.yml
  15. 61
      dev/docker-mysql/docker-compose.yml
  16. 7
      dev/docker-mysql/init.sh
  17. 21
      dev/docker-postgres/Dockerfile
  18. 0
      dev/docker-postgres/config.yml
  19. 4
      dev/docker-postgres/docker-compose.yml
  20. 4
      dev/docker-postgres/init.sh
  21. 21
      dev/docker-sqlite/Dockerfile
  22. 10
      dev/docker-sqlite/config.yml
  23. 35
      dev/docker-sqlite/docker-compose.yml
  24. 6
      dev/docker-sqlite/init.sh
  25. 2
      server/core/config.js
  26. 2
      server/core/localization.js
  27. 9
      server/models/authentication.js
  28. 7
      server/models/editors.js
  29. 4
      server/models/groups.js
  30. 7
      server/models/locales.js
  31. 7
      server/models/loggers.js
  32. 7
      server/models/renderers.js
  33. 7
      server/models/searchEngines.js
  34. 7
      server/models/settings.js
  35. 7
      server/models/storage.js

1
CHANGELOG.md

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

22
Makefile

@ -1,4 +1,5 @@
SHELL := /bin/bash
DEVDB := postgres
start: ## Start Wiki.js in production mode
node wiki start
@ -23,27 +24,30 @@ test: ## Run code linting tests
pug-lint server/views && jest
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/docker-compose.yml -p wiki --project-directory . exec wiki yarn dev
docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . up -d
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-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
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
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'
docker-compose -f ./dev/docker/docker-compose.yml -p wiki --project-directory . exec redis redis-cli flushall
[[ "${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
[[ "${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-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-compose -f ./dev/docker/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 . run wiki yarn build
docker-compose -f ./dev/docker-${DEVDB}/docker-compose.yml -p wiki --project-directory . down
help: ## Display help
@echo ''

2
dev/build/Dockerfile

@ -29,7 +29,7 @@ FROM node:10.15-alpine
LABEL maintainer="requarks.io"
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/* && \
mkdir -p /wiki && \
mkdir -p /logs

dev/docker/wait.sh → dev/docker-common/wait.sh

21
dev/docker-mariadb/Dockerfile

@ -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"]

14
dev/docker-mariadb/config.yml

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

61
dev/docker-mariadb/docker-compose.yml

@ -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:

7
dev/docker-mariadb/init.sh

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

dev/docker/Dockerfile → dev/docker-mssql/Dockerfile

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

14
dev/docker-mssql/config.yml

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

60
dev/docker-mssql/docker-compose.yml

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

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

21
dev/docker-mysql/Dockerfile

@ -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"]

14
dev/docker-mysql/config.yml

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

61
dev/docker-mysql/docker-compose.yml

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

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

21
dev/docker-postgres/Dockerfile

@ -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"]

dev/docker/config.yml → dev/docker-postgres/config.yml

dev/docker/docker-compose.yml → dev/docker-postgres/docker-compose.yml

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

dev/docker/init.sh → dev/docker-postgres/init.sh

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

21
dev/docker-sqlite/Dockerfile

@ -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"]

10
dev/docker-sqlite/config.yml

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

35
dev/docker-sqlite/docker-compose.yml

@ -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:

6
dev/docker-sqlite/init.sh

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

2
server/core/config.js

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

2
server/core/localization.js

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

9
server/models/authentication.js

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

7
server/models/editors.js

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

4
server/models/groups.js

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

7
server/models/locales.js

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

7
server/models/loggers.js

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

7
server/models/renderers.js

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

7
server/models/searchEngines.js

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

7
server/models/settings.js

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

7
server/models/storage.js

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

Loading…
Cancel
Save