2.0.0-beta.11.js 2.43 KB
Newer Older
Nick's avatar
Nick committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
exports.up = knex => {
  return knex.schema
    .renameTable('pageHistory', 'pageHistory_old')
    .createTable('pageHistory', table => {
      table.increments('id').primary()
      table.string('path').notNullable()
      table.string('hash').notNullable()
      table.string('title').notNullable()
      table.string('description')
      table.boolean('isPrivate').notNullable().defaultTo(false)
      table.boolean('isPublished').notNullable().defaultTo(false)
      table.string('publishStartDate')
      table.string('publishEndDate')
      table.text('content')
      table.string('contentType').notNullable()
      table.string('createdAt').notNullable()
      table.string('action').defaultTo('updated')

Nick's avatar
Nick committed
19
      table.integer('pageId').unsigned()
Nick's avatar
Nick committed
20
      table.string('editorKey').references('key').inTable('editors')
Nick's avatar
Nick committed
21
      table.string('localeCode', 5).references('code').inTable('locales')
Nick's avatar
Nick committed
22 23
      table.integer('authorId').unsigned().references('id').inTable('users')
    })
Nick's avatar
Nick committed
24
    .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;`)
Nick's avatar
Nick committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    .dropTable('pageHistory_old')
}

exports.down = knex => {
  return knex.schema
    .renameTable('pageHistory', 'pageHistory_old')
    .createTable('pageHistory', table => {
      table.increments('id').primary()
      table.string('path').notNullable()
      table.string('hash').notNullable()
      table.string('title').notNullable()
      table.string('description')
      table.boolean('isPrivate').notNullable().defaultTo(false)
      table.boolean('isPublished').notNullable().defaultTo(false)
      table.string('publishStartDate')
      table.string('publishEndDate')
      table.text('content')
      table.string('contentType').notNullable()
      table.string('createdAt').notNullable()

      table.integer('pageId').unsigned().references('id').inTable('pages')
      table.string('editorKey').references('key').inTable('editors')
Nick's avatar
Nick committed
47
      table.string('localeCode', 5).references('code').inTable('locales')
Nick's avatar
Nick committed
48 49 50 51 52
      table.integer('authorId').unsigned().references('id').inTable('users')
    })
    .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;')
    .dropTable('pageHistory_old')
}