From 44a1c8699f4521d1bdeecca26c24af7cde8da3fc Mon Sep 17 00:00:00 2001 From: AchimHentschel Date: Sat, 26 Oct 2019 00:28:41 +0200 Subject: [PATCH] fix: MSSQL - adds IDENTITY_INSERT in rebuild-tree.js #1125 (#1130) Fixes issue when tree is being rebuilt with mssql backend --- server/jobs/rebuild-tree.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/jobs/rebuild-tree.js b/server/jobs/rebuild-tree.js index 81e7ecf4..0ce0cb72 100644 --- a/server/jobs/rebuild-tree.js +++ b/server/jobs/rebuild-tree.js @@ -53,7 +53,16 @@ module.exports = async (pageId) => { await WIKI.models.knex.table('pageTree').truncate() if (tree.length > 0) { - await WIKI.models.knex.table('pageTree').insert(tree) + 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.destroy()