fix: cascade delete pageTree on page delete (#1119)

This commit is contained in:
NGPixel 2019-10-22 22:04:14 -04:00
parent 7c8604b97c
commit ab8391c085
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,35 @@
exports.up = knex => {
return knex.schema
.dropTable('pageTree')
.createTable('pageTree', table => {
table.increments('id').primary()
table.string('path').notNullable()
table.integer('depth').unsigned().notNullable()
table.string('title').notNullable()
table.boolean('isPrivate').notNullable().defaultTo(false)
table.boolean('isFolder').notNullable().defaultTo(false)
table.string('privateNS')
table.integer('parent').unsigned().references('id').inTable('pageTree').onDelete('CASCADE')
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
table.string('localeCode', 5).references('code').inTable('locales')
})
}
exports.down = knex => {
return knex.schema
.dropTable('pageTree')
.createTable('pageTree', table => {
table.increments('id').primary()
table.string('path').notNullable()
table.integer('depth').unsigned().notNullable()
table.string('title').notNullable()
table.boolean('isPrivate').notNullable().defaultTo(false)
table.boolean('isFolder').notNullable().defaultTo(false)
table.string('privateNS')
table.integer('parent').unsigned().references('id').inTable('pageTree')
table.integer('pageId').unsigned().references('id').inTable('pages')
table.string('localeCode', 5).references('code').inTable('locales')
})
}

View File

@ -0,0 +1,23 @@
exports.up = knex => {
return knex.schema
.table('pageTree', table => {
table.dropColumn('parent')
table.dropColumn('pageId')
})
.table('pageTree', table => {
table.integer('parent').unsigned().references('id').inTable('pageTree').onDelete('CASCADE')
table.integer('pageId').unsigned().references('id').inTable('pages').onDelete('CASCADE')
})
}
exports.down = knex => {
return knex.schema
.table('pageTree', table => {
table.dropColumn('parent')
table.dropColumn('pageId')
})
.table('pageTree', table => {
table.integer('parent').unsigned().references('id').inTable('pageTree')
table.integer('pageId').unsigned().references('id').inTable('pages')
})
}