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
You need to sign in or sign up before continuing.
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 => {
...
@@ -2,7 +2,7 @@ exports.up = knex => {
return
knex
.
schema
return
knex
.
schema
.
dropTable
(
'pageTree'
)
.
dropTable
(
'pageTree'
)
.
createTable
(
'pageTree'
,
table
=>
{
.
createTable
(
'pageTree'
,
table
=>
{
table
.
in
crements
(
'id'
).
primary
()
table
.
in
teger
(
'id'
).
primary
()
table
.
string
(
'path'
).
notNullable
()
table
.
string
(
'path'
).
notNullable
()
table
.
integer
(
'depth'
).
unsigned
().
notNullable
()
table
.
integer
(
'depth'
).
unsigned
().
notNullable
()
table
.
string
(
'title'
).
notNullable
()
table
.
string
(
'title'
).
notNullable
()
...
@@ -20,7 +20,7 @@ exports.down = knex => {
...
@@ -20,7 +20,7 @@ exports.down = knex => {
return
knex
.
schema
return
knex
.
schema
.
dropTable
(
'pageTree'
)
.
dropTable
(
'pageTree'
)
.
createTable
(
'pageTree'
,
table
=>
{
.
createTable
(
'pageTree'
,
table
=>
{
table
.
in
crements
(
'id'
).
primary
()
table
.
in
teger
(
'id'
).
primary
()
table
.
string
(
'path'
).
notNullable
()
table
.
string
(
'path'
).
notNullable
()
table
.
integer
(
'depth'
).
unsigned
().
notNullable
()
table
.
integer
(
'depth'
).
unsigned
().
notNullable
()
table
.
string
(
'title'
).
notNullable
()
table
.
string
(
'title'
).
notNullable
()
...
...
server/db/migrations/2.0.0-rc.2.js
View file @
820cc77a
/* global WIKI */
exports
.
up
=
knex
=>
{
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
return
knex
.
schema
.
table
(
'pageTree'
,
table
=>
{
.
dropTable
(
'pageTree'
)
table
.
dropColumn
(
'parent'
)
.
createTable
(
'pageTree'
,
table
=>
{
table
.
dropColumn
(
'pageId'
)
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
(
'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
.
integer
(
'pageId'
).
unsigned
().
references
(
'id'
).
inTable
(
'pages'
).
onDelete
(
'CASCADE'
)
table
.
string
(
'localeCode'
,
5
).
references
(
'code'
).
inTable
(
'locales'
)
})
})
}
}
exports
.
down
=
knex
=>
{
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
return
knex
.
schema
.
table
(
'pageTree'
,
table
=>
{
.
dropTable
(
'pageTree'
)
table
.
dropColumn
(
'parent'
)
.
createTable
(
'pageTree'
,
table
=>
{
table
.
dropColumn
(
'pageId'
)
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
(
'pageTree'
,
table
=>
{
table
.
integer
(
'parent'
).
unsigned
().
references
(
'id'
).
inTable
(
'pageTree'
)
table
.
integer
(
'parent'
).
unsigned
().
references
(
'id'
).
inTable
(
'pageTree'
)
table
.
integer
(
'pageId'
).
unsigned
().
references
(
'id'
).
inTable
(
'pages'
)
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) => {
...
@@ -53,16 +53,7 @@ module.exports = async (pageId) => {
await
WIKI
.
models
.
knex
.
table
(
'pageTree'
).
truncate
()
await
WIKI
.
models
.
knex
.
table
(
'pageTree'
).
truncate
()
if
(
tree
.
length
>
0
)
{
if
(
tree
.
length
>
0
)
{
const
{
bindings
,
sql
}
=
WIKI
.
models
.
knex
.
table
(
'pageTree'
).
insert
(
tree
).
toSQL
();
await
WIKI
.
models
.
knex
.
table
(
'pageTree'
).
insert
(
tree
)
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
.
destroy
()
await
WIKI
.
models
.
knex
.
destroy
()
...
...
server/models/pages.js
View file @
820cc77a
...
@@ -568,8 +568,8 @@ module.exports = class Page extends Model {
...
@@ -568,8 +568,8 @@ module.exports = class Page extends Model {
}
}
let
affectedHashes
=
[]
let
affectedHashes
=
[]
// -> Perform replace and return affected page hashes (POSTGRES
, MSSQL
only)
// -> Perform replace and return affected page hashes (POSTGRES only)
if
(
WIKI
.
config
.
db
.
type
===
'postgres'
||
WIKI
.
config
.
db
.
type
===
'mssql'
)
{
if
(
WIKI
.
config
.
db
.
type
===
'postgres'
)
{
affectedHashes
=
await
WIKI
.
models
.
pages
.
query
()
affectedHashes
=
await
WIKI
.
models
.
pages
.
query
()
.
returning
(
'hash'
)
.
returning
(
'hash'
)
.
patch
({
.
patch
({
...
@@ -583,7 +583,7 @@ module.exports = class Page extends Model {
...
@@ -583,7 +583,7 @@ module.exports = class Page extends Model {
})
})
.
pluck
(
'hash'
)
.
pluck
(
'hash'
)
}
else
{
}
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
()
await
WIKI
.
models
.
pages
.
query
()
.
patch
({
.
patch
({
render
:
WIKI
.
models
.
knex
.
raw
(
'REPLACE(??, ?, ?)'
,
[
'render'
,
replaceArgs
.
from
,
replaceArgs
.
to
])
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')
...
@@ -9,7 +9,6 @@ const https = require('https')
const
Promise
=
require
(
'bluebird'
)
const
Promise
=
require
(
'bluebird'
)
const
fs
=
require
(
'fs-extra'
)
const
fs
=
require
(
'fs-extra'
)
const
_
=
require
(
'lodash'
)
const
_
=
require
(
'lodash'
)
const
cfgHelper
=
require
(
'./helpers/config'
)
const
crypto
=
Promise
.
promisifyAll
(
require
(
'crypto'
))
const
crypto
=
Promise
.
promisifyAll
(
require
(
'crypto'
))
const
pem2jwk
=
require
(
'pem-jwk'
).
pem2jwk
const
pem2jwk
=
require
(
'pem-jwk'
).
pem2jwk
const
semver
=
require
(
'semver'
)
const
semver
=
require
(
'semver'
)
...
@@ -203,14 +202,14 @@ module.exports = () => {
...
@@ -203,14 +202,14 @@ module.exports = () => {
WIKI
.
logger
.
info
(
'Creating default groups...'
)
WIKI
.
logger
.
info
(
'Creating default groups...'
)
const
adminGroup
=
await
WIKI
.
models
.
groups
.
query
().
insert
({
const
adminGroup
=
await
WIKI
.
models
.
groups
.
query
().
insert
({
id
:
1
,
...(
WIKI
.
config
.
db
.
type
!==
`mssql`
&&
{
id
:
1
})
,
name
:
'Administrators'
,
name
:
'Administrators'
,
permissions
:
JSON
.
stringify
([
'manage:system'
]),
permissions
:
JSON
.
stringify
([
'manage:system'
]),
pageRules
:
JSON
.
stringify
([]),
pageRules
:
JSON
.
stringify
([]),
isSystem
:
true
isSystem
:
true
})
})
const
guestGroup
=
await
WIKI
.
models
.
groups
.
query
().
insert
({
const
guestGroup
=
await
WIKI
.
models
.
groups
.
query
().
insert
({
id
:
2
,
...(
WIKI
.
config
.
db
.
type
!==
`mssql`
&&
{
id
:
2
})
,
name
:
'Guests'
,
name
:
'Guests'
,
permissions
:
JSON
.
stringify
([
'read:pages'
,
'read:assets'
,
'read:comments'
]),
permissions
:
JSON
.
stringify
([
'read:pages'
,
'read:assets'
,
'read:comments'
]),
pageRules
:
JSON
.
stringify
([
pageRules
:
JSON
.
stringify
([
...
@@ -218,6 +217,9 @@ module.exports = () => {
...
@@ -218,6 +217,9 @@ module.exports = () => {
]),
]),
isSystem
:
true
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
// Load authentication strategies + enable local
await
WIKI
.
models
.
authentication
.
refreshStrategiesFromDisk
()
await
WIKI
.
models
.
authentication
.
refreshStrategiesFromDisk
()
...
@@ -244,12 +246,8 @@ module.exports = () => {
...
@@ -244,12 +246,8 @@ module.exports = () => {
// Create root administrator
// Create root administrator
WIKI
.
logger
.
info
(
'Creating 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
({
const
adminUser
=
await
WIKI
.
models
.
users
.
query
().
insert
({
id
:
1
,
...(
WIKI
.
config
.
db
.
type
!==
`mssql`
&&
{
id
:
1
})
,
email
:
req
.
body
.
adminEmail
,
email
:
req
.
body
.
adminEmail
,
provider
:
'local'
,
provider
:
'local'
,
password
:
req
.
body
.
adminPassword
,
password
:
req
.
body
.
adminPassword
,
...
@@ -264,12 +262,8 @@ module.exports = () => {
...
@@ -264,12 +262,8 @@ module.exports = () => {
// Create Guest account
// Create Guest account
WIKI
.
logger
.
info
(
'Creating 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
({
const
guestUser
=
await
WIKI
.
models
.
users
.
query
().
insert
({
id
:
2
,
...(
WIKI
.
config
.
db
.
type
!==
`mssql`
&&
{
id
:
2
})
,
provider
:
'local'
,
provider
:
'local'
,
email
:
'guest@example.com'
,
email
:
'guest@example.com'
,
name
:
'Guest'
,
name
:
'Guest'
,
...
@@ -282,11 +276,13 @@ module.exports = () => {
...
@@ -282,11 +276,13 @@ module.exports = () => {
isVerified
:
true
isVerified
:
true
})
})
await
guestUser
.
$relatedQuery
(
'groups'
).
relate
(
guestGroup
.
id
)
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
// Create site nav
WIKI
.
logger
.
info
(
'Creating default site navigation'
)
WIKI
.
logger
.
info
(
'Creating default site navigation'
)
await
WIKI
.
models
.
navigation
.
query
().
delete
().
where
({
key
:
'site'
})
await
WIKI
.
models
.
navigation
.
query
().
insert
({
await
WIKI
.
models
.
navigation
.
query
().
insert
({
key
:
'site'
,
key
:
'site'
,
config
:
[
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