wikijs-fork/server/db/migrations-sqlite/2.0.0-beta.11.js
2019-02-22 17:05:49 -05:00

52 lines
2.4 KiB
JavaScript

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')
table.string('editorKey').references('key').inTable('editors')
table.string('localeCode', 2).references('code').inTable('locales')
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,'updated' AS action,editorKey,localeCode,authorId FROM pageHistory_old;`)
.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')
table.string('localeCode', 2).references('code').inTable('locales')
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')
}