2.0.0-beta.11.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.string('editorKey').references('key').inTable('editors')
  19. table.string('localeCode', 2).references('code').inTable('locales')
  20. table.integer('authorId').unsigned().references('id').inTable('users')
  21. })
  22. .raw(`INSERT INTO pageHistory SELECT id,path,hash,title,description,isPrivate,isPublished,publishStartDate,publishEndDate,content,contentType,createdAt,'updated' AS action,editorKey,localeCode,authorId FROM pageHistory_old;`)
  23. .dropTable('pageHistory_old')
  24. }
  25. exports.down = knex => {
  26. return knex.schema
  27. .renameTable('pageHistory', 'pageHistory_old')
  28. .createTable('pageHistory', table => {
  29. table.increments('id').primary()
  30. table.string('path').notNullable()
  31. table.string('hash').notNullable()
  32. table.string('title').notNullable()
  33. table.string('description')
  34. table.boolean('isPrivate').notNullable().defaultTo(false)
  35. table.boolean('isPublished').notNullable().defaultTo(false)
  36. table.string('publishStartDate')
  37. table.string('publishEndDate')
  38. table.text('content')
  39. table.string('contentType').notNullable()
  40. table.string('createdAt').notNullable()
  41. table.integer('pageId').unsigned().references('id').inTable('pages')
  42. table.string('editorKey').references('key').inTable('editors')
  43. table.string('localeCode', 2).references('code').inTable('locales')
  44. table.integer('authorId').unsigned().references('id').inTable('users')
  45. })
  46. .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;')
  47. .dropTable('pageHistory_old')
  48. }