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.

52 lines
2.4 KiB

  1. exports.up = knex => {
  2. return knex.schema
  3. .renameTable('pageHistory', 'pageHistory_old')
  4. .createTable('pageHistory', table => {
  5. table.increments('id').primary()
  6. table.string('path').notNullable()
  7. table.string('hash').notNullable()
  8. table.string('title').notNullable()
  9. table.string('description')
  10. table.boolean('isPrivate').notNullable().defaultTo(false)
  11. table.boolean('isPublished').notNullable().defaultTo(false)
  12. table.string('publishStartDate')
  13. table.string('publishEndDate')
  14. table.text('content')
  15. table.string('contentType').notNullable()
  16. table.string('createdAt').notNullable()
  17. table.string('action').defaultTo('updated')
  18. table.integer('pageId').unsigned()
  19. table.string('editorKey').references('key').inTable('editors')
  20. table.string('localeCode', 2).references('code').inTable('locales')
  21. table.integer('authorId').unsigned().references('id').inTable('users')
  22. })
  23. .raw(`INSERT INTO pageHistory SELECT id,path,hash,title,description,isPrivate,isPublished,publishStartDate,publishEndDate,content,contentType,createdAt,'updated' AS action,pageId,editorKey,localeCode,authorId FROM pageHistory_old;`)
  24. .dropTable('pageHistory_old')
  25. }
  26. exports.down = knex => {
  27. return knex.schema
  28. .renameTable('pageHistory', 'pageHistory_old')
  29. .createTable('pageHistory', table => {
  30. table.increments('id').primary()
  31. table.string('path').notNullable()
  32. table.string('hash').notNullable()
  33. table.string('title').notNullable()
  34. table.string('description')
  35. table.boolean('isPrivate').notNullable().defaultTo(false)
  36. table.boolean('isPublished').notNullable().defaultTo(false)
  37. table.string('publishStartDate')
  38. table.string('publishEndDate')
  39. table.text('content')
  40. table.string('contentType').notNullable()
  41. table.string('createdAt').notNullable()
  42. table.integer('pageId').unsigned().references('id').inTable('pages')
  43. table.string('editorKey').references('key').inTable('editors')
  44. table.string('localeCode', 2).references('code').inTable('locales')
  45. table.integer('authorId').unsigned().references('id').inTable('users')
  46. })
  47. .raw('INSERT INTO pageHistory SELECT id,path,hash,title,description,isPrivate,isPublished,publishStartDate,publishEndDate,content,contentType,createdAt,NULL as pageId,editorKey,localeCode,authorId FROM pageHistory_old;')
  48. .dropTable('pageHistory_old')
  49. }