Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
820cc77a
Commit
820cc77a
authored
Oct 25, 2019
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: MSSQL - setup + pageTree + page delete
parent
ea5c4ea3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
36 deletions
+53
-36
2.0.0-rc.2.js
server/db/migrations-sqlite/2.0.0-rc.2.js
+2
-2
2.0.0-rc.2.js
server/db/migrations/2.0.0-rc.2.js
+37
-7
rebuild-tree.js
server/jobs/rebuild-tree.js
+1
-10
pages.js
server/models/pages.js
+3
-3
setup.js
server/setup.js
+10
-14
No files found.
server/db/migrations-sqlite/2.0.0-rc.2.js
View file @
820cc77a
...
...
@@ -2,7 +2,7 @@ exports.up = knex => {
return
knex
.
schema
.
dropTable
(
'pageTree'
)
.
createTable
(
'pageTree'
,
table
=>
{
table
.
in
crements
(
'id'
).
primary
()
table
.
in
teger
(
'id'
).
primary
()
table
.
string
(
'path'
).
notNullable
()
table
.
integer
(
'depth'
).
unsigned
().
notNullable
()
table
.
string
(
'title'
).
notNullable
()
...
...
@@ -20,7 +20,7 @@ exports.down = knex => {
return
knex
.
schema
.
dropTable
(
'pageTree'
)
.
createTable
(
'pageTree'
,
table
=>
{
table
.
in
crements
(
'id'
).
primary
()
table
.
in
teger
(
'id'
).
primary
()
table
.
string
(
'path'
).
notNullable
()
table
.
integer
(
'depth'
).
unsigned
().
notNullable
()
table
.
string
(
'title'
).
notNullable
()
...
...
server/db/migrations/2.0.0-rc.2.js
View file @
820cc77a
/* global WIKI */
exports
.
up
=
knex
=>
{
const
dbCompat
=
{
charset
:
(
WIKI
.
config
.
db
.
type
===
`mysql`
||
WIKI
.
config
.
db
.
type
===
`mariadb`
),
selfCascadeDelete
:
WIKI
.
config
.
db
.
type
!==
'mssql'
}
return
knex
.
schema
.
table
(
'pageTree'
,
table
=>
{
table
.
dropColumn
(
'parent'
)
table
.
dropColumn
(
'pageId'
)
.
dropTable
(
'pageTree'
)
.
createTable
(
'pageTree'
,
table
=>
{
if
(
dbCompat
.
charset
)
{
table
.
charset
(
'utf8mb4'
)
}
table
.
integer
(
'id'
).
unsigned
().
primary
()
table
.
string
(
'path'
).
notNullable
()
table
.
integer
(
'depth'
).
unsigned
().
notNullable
()
table
.
string
(
'title'
).
notNullable
()
table
.
boolean
(
'isPrivate'
).
notNullable
().
defaultTo
(
false
)
table
.
boolean
(
'isFolder'
).
notNullable
().
defaultTo
(
false
)
table
.
string
(
'privateNS'
)
})
.
table
(
'pageTree'
,
table
=>
{
table
.
integer
(
'parent'
).
unsigned
().
references
(
'id'
).
inTable
(
'pageTree'
).
onDelete
(
'CASCADE'
)
if
(
dbCompat
.
selfCascadeDelete
)
{
table
.
integer
(
'parent'
).
unsigned
().
references
(
'id'
).
inTable
(
'pageTree'
).
onDelete
(
'CASCADE'
)
}
else
{
table
.
integer
(
'parent'
).
unsigned
()
}
table
.
integer
(
'pageId'
).
unsigned
().
references
(
'id'
).
inTable
(
'pages'
).
onDelete
(
'CASCADE'
)
table
.
string
(
'localeCode'
,
5
).
references
(
'code'
).
inTable
(
'locales'
)
})
}
exports
.
down
=
knex
=>
{
const
dbCompat
=
{
charset
:
(
WIKI
.
config
.
db
.
type
===
`mysql`
||
WIKI
.
config
.
db
.
type
===
`mariadb`
),
selfCascadeDelete
:
WIKI
.
config
.
db
.
type
!==
'mssql'
}
return
knex
.
schema
.
table
(
'pageTree'
,
table
=>
{
table
.
dropColumn
(
'parent'
)
table
.
dropColumn
(
'pageId'
)
.
dropTable
(
'pageTree'
)
.
createTable
(
'pageTree'
,
table
=>
{
if
(
dbCompat
.
charset
)
{
table
.
charset
(
'utf8mb4'
)
}
table
.
integer
(
'id'
).
primary
()
table
.
string
(
'path'
).
notNullable
()
table
.
integer
(
'depth'
).
unsigned
().
notNullable
()
table
.
string
(
'title'
).
notNullable
()
table
.
boolean
(
'isPrivate'
).
notNullable
().
defaultTo
(
false
)
table
.
boolean
(
'isFolder'
).
notNullable
().
defaultTo
(
false
)
table
.
string
(
'privateNS'
)
})
.
table
(
'pageTree'
,
table
=>
{
table
.
integer
(
'parent'
).
unsigned
().
references
(
'id'
).
inTable
(
'pageTree'
)
table
.
integer
(
'pageId'
).
unsigned
().
references
(
'id'
).
inTable
(
'pages'
)
table
.
string
(
'localeCode'
,
5
).
references
(
'code'
).
inTable
(
'locales'
)
})
}
server/jobs/rebuild-tree.js
View file @
820cc77a
...
...
@@ -53,16 +53,7 @@ module.exports = async (pageId) => {
await
WIKI
.
models
.
knex
.
table
(
'pageTree'
).
truncate
()
if
(
tree
.
length
>
0
)
{
const
{
bindings
,
sql
}
=
WIKI
.
models
.
knex
.
table
(
'pageTree'
).
insert
(
tree
).
toSQL
();
if
(
WIKI
.
config
.
db
.
type
===
'mssql'
)
{
await
WIKI
.
models
.
knex
.
raw
(
sql
,
bindings
).
wrap
(
'SET IDENTITY_INSERT pageTree ON;'
,
'SET IDENTITY_INSERT pageTree OFF;'
,
)
}
else
{
await
WIKI
.
models
.
knex
.
raw
(
sql
,
bindings
)
}
// await WIKI.models.knex.table('pageTree').insert(tree)
await
WIKI
.
models
.
knex
.
table
(
'pageTree'
).
insert
(
tree
)
}
await
WIKI
.
models
.
knex
.
destroy
()
...
...
server/models/pages.js
View file @
820cc77a
...
...
@@ -568,8 +568,8 @@ module.exports = class Page extends Model {
}
let
affectedHashes
=
[]
// -> Perform replace and return affected page hashes (POSTGRES
, MSSQL
only)
if
(
WIKI
.
config
.
db
.
type
===
'postgres'
||
WIKI
.
config
.
db
.
type
===
'mssql'
)
{
// -> Perform replace and return affected page hashes (POSTGRES only)
if
(
WIKI
.
config
.
db
.
type
===
'postgres'
)
{
affectedHashes
=
await
WIKI
.
models
.
pages
.
query
()
.
returning
(
'hash'
)
.
patch
({
...
...
@@ -583,7 +583,7 @@ module.exports = class Page extends Model {
})
.
pluck
(
'hash'
)
}
else
{
// -> Perform replace, then query affected page hashes (MYSQL, MARIADB, SQLITE only)
// -> Perform replace, then query affected page hashes (MYSQL, MARIADB,
MSSQL,
SQLITE only)
await
WIKI
.
models
.
pages
.
query
()
.
patch
({
render
:
WIKI
.
models
.
knex
.
raw
(
'REPLACE(??, ?, ?)'
,
[
'render'
,
replaceArgs
.
from
,
replaceArgs
.
to
])
...
...
server/setup.js
View file @
820cc77a
...
...
@@ -9,7 +9,6 @@ const https = require('https')
const
Promise
=
require
(
'bluebird'
)
const
fs
=
require
(
'fs-extra'
)
const
_
=
require
(
'lodash'
)
const
cfgHelper
=
require
(
'./helpers/config'
)
const
crypto
=
Promise
.
promisifyAll
(
require
(
'crypto'
))
const
pem2jwk
=
require
(
'pem-jwk'
).
pem2jwk
const
semver
=
require
(
'semver'
)
...
...
@@ -203,14 +202,14 @@ module.exports = () => {
WIKI
.
logger
.
info
(
'Creating default groups...'
)
const
adminGroup
=
await
WIKI
.
models
.
groups
.
query
().
insert
({
id
:
1
,
...(
WIKI
.
config
.
db
.
type
!==
`mssql`
&&
{
id
:
1
})
,
name
:
'Administrators'
,
permissions
:
JSON
.
stringify
([
'manage:system'
]),
pageRules
:
JSON
.
stringify
([]),
isSystem
:
true
})
const
guestGroup
=
await
WIKI
.
models
.
groups
.
query
().
insert
({
id
:
2
,
...(
WIKI
.
config
.
db
.
type
!==
`mssql`
&&
{
id
:
2
})
,
name
:
'Guests'
,
permissions
:
JSON
.
stringify
([
'read:pages'
,
'read:assets'
,
'read:comments'
]),
pageRules
:
JSON
.
stringify
([
...
...
@@ -218,6 +217,9 @@ module.exports = () => {
]),
isSystem
:
true
})
if
(
adminGroup
.
id
!==
1
||
guestGroup
.
id
!==
2
)
{
throw
new
Error
(
'Incorrect groups auto-increment configuration! Should start at 0 and increment by 1. Contact your database administrator.'
)
}
// Load authentication strategies + enable local
await
WIKI
.
models
.
authentication
.
refreshStrategiesFromDisk
()
...
...
@@ -244,12 +246,8 @@ module.exports = () => {
// Create root administrator
WIKI
.
logger
.
info
(
'Creating root administrator...'
)
await
WIKI
.
models
.
users
.
query
().
delete
().
where
({
providerKey
:
'local'
,
email
:
req
.
body
.
adminEmail
}).
orWhere
(
'id'
,
1
)
const
adminUser
=
await
WIKI
.
models
.
users
.
query
().
insert
({
id
:
1
,
...(
WIKI
.
config
.
db
.
type
!==
`mssql`
&&
{
id
:
1
})
,
email
:
req
.
body
.
adminEmail
,
provider
:
'local'
,
password
:
req
.
body
.
adminPassword
,
...
...
@@ -264,12 +262,8 @@ module.exports = () => {
// Create Guest account
WIKI
.
logger
.
info
(
'Creating guest account...'
)
await
WIKI
.
models
.
users
.
query
().
delete
().
where
({
providerKey
:
'local'
,
email
:
'guest@example.com'
}).
orWhere
(
'id'
,
2
)
const
guestUser
=
await
WIKI
.
models
.
users
.
query
().
insert
({
id
:
2
,
...(
WIKI
.
config
.
db
.
type
!==
`mssql`
&&
{
id
:
2
})
,
provider
:
'local'
,
email
:
'guest@example.com'
,
name
:
'Guest'
,
...
...
@@ -282,11 +276,13 @@ module.exports = () => {
isVerified
:
true
})
await
guestUser
.
$relatedQuery
(
'groups'
).
relate
(
guestGroup
.
id
)
if
(
adminUser
.
id
!==
1
||
guestUser
.
id
!==
2
)
{
throw
new
Error
(
'Incorrect groups auto-increment configuration! Should start at 0 and increment by 1. Contact your database administrator.'
)
}
// Create site nav
WIKI
.
logger
.
info
(
'Creating default site navigation'
)
await
WIKI
.
models
.
navigation
.
query
().
delete
().
where
({
key
:
'site'
})
await
WIKI
.
models
.
navigation
.
query
().
insert
({
key
:
'site'
,
config
:
[
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment