fix: mssql + older mariadb migration 2.2.17 failure

This commit is contained in:
NGPixel 2020-04-10 16:06:43 -04:00
parent 77548c8778
commit 245104c6ae

View File

@ -6,10 +6,13 @@ exports.up = async knex => {
let sqlVersionDate = '' let sqlVersionDate = ''
switch (WIKI.config.db.type) { switch (WIKI.config.db.type) {
case 'postgres': case 'postgres':
case 'mssql':
sqlVersionDate = 'UPDATE "pageHistory" h1 SET "versionDate" = COALESCE((SELECT prev."createdAt" FROM "pageHistory" prev WHERE prev."pageId" = h1."pageId" AND prev.id < h1.id ORDER BY prev.id DESC LIMIT 1), h1."createdAt")' sqlVersionDate = 'UPDATE "pageHistory" h1 SET "versionDate" = COALESCE((SELECT prev."createdAt" FROM "pageHistory" prev WHERE prev."pageId" = h1."pageId" AND prev.id < h1.id ORDER BY prev.id DESC LIMIT 1), h1."createdAt")'
break break
case 'mssql':
sqlVersionDate = 'UPDATE h1 SET "versionDate" = COALESCE((SELECT TOP 1 prev."createdAt" FROM "pageHistory" prev WHERE prev."pageId" = h1."pageId" AND prev.id < h1.id ORDER BY prev.id DESC), h1."createdAt") FROM "pageHistory" h1'
break
case 'mysql': case 'mysql':
case 'mariadb':
// -> Fix for 2.2.50 failed migration // -> Fix for 2.2.50 failed migration
const pageHistoryColumns = await knex.schema.raw('SHOW COLUMNS FROM pageHistory') const pageHistoryColumns = await knex.schema.raw('SHOW COLUMNS FROM pageHistory')
if (_.some(pageHistoryColumns[0], ['Field', 'versionDate'])) { if (_.some(pageHistoryColumns[0], ['Field', 'versionDate'])) {
@ -20,9 +23,9 @@ exports.up = async knex => {
sqlVersionDate = `UPDATE pageHistory AS h1 INNER JOIN pageHistory AS h2 ON h2.id = (SELECT prev.id FROM (SELECT * FROM pageHistory) AS prev WHERE prev.pageId = h1.pageId AND prev.id < h1.id ORDER BY prev.id DESC LIMIT 1) SET h1.versionDate = h2.createdAt` sqlVersionDate = `UPDATE pageHistory AS h1 INNER JOIN pageHistory AS h2 ON h2.id = (SELECT prev.id FROM (SELECT * FROM pageHistory) AS prev WHERE prev.pageId = h1.pageId AND prev.id < h1.id ORDER BY prev.id DESC LIMIT 1) SET h1.versionDate = h2.createdAt`
break break
case 'mariadb': // case 'mariadb':
sqlVersionDate = `UPDATE pageHistory AS h1 INNER JOIN pageHistory AS h2 ON h2.id = (SELECT prev.id FROM pageHistory AS prev WHERE prev.pageId = h1.pageId AND prev.id < h1.id ORDER BY prev.id DESC LIMIT 1) SET h1.versionDate = h2.createdAt` // sqlVersionDate = `UPDATE pageHistory AS h1 INNER JOIN pageHistory AS h2 ON h2.id = (SELECT prev.id FROM pageHistory AS prev WHERE prev.pageId = h1.pageId AND prev.id < h1.id ORDER BY prev.id DESC LIMIT 1) SET h1.versionDate = h2.createdAt`
break // break
} }
await knex.schema await knex.schema
.alterTable('pageHistory', table => { .alterTable('pageHistory', table => {