You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
866 B

  1. /* global WIKI */
  2. exports.up = knex => {
  3. let sqlVersionDate = ''
  4. switch (WIKI.config.db.type) {
  5. case 'postgres':
  6. case 'mssql':
  7. 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)'
  8. break
  9. case 'mysql':
  10. case 'mariadb':
  11. 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`
  12. break
  13. }
  14. return knex.schema
  15. .alterTable('pageHistory', table => {
  16. table.string('versionDate').notNullable().defaultTo('')
  17. })
  18. .raw(sqlVersionDate)
  19. }
  20. exports.down = knex => { }