From ab8391c085773f99ca1f5fd3fe267527e8b40757 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Tue, 22 Oct 2019 22:04:14 -0400 Subject: [PATCH] fix: cascade delete pageTree on page delete (#1119) --- server/db/migrations-sqlite/2.0.0-rc.2.js | 35 +++++++++++++++++++++++ server/db/migrations/2.0.0-rc.2.js | 23 +++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 server/db/migrations-sqlite/2.0.0-rc.2.js create mode 100644 server/db/migrations/2.0.0-rc.2.js diff --git a/server/db/migrations-sqlite/2.0.0-rc.2.js b/server/db/migrations-sqlite/2.0.0-rc.2.js new file mode 100644 index 00000000..b5df6e3f --- /dev/null +++ b/server/db/migrations-sqlite/2.0.0-rc.2.js @@ -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') + }) +} diff --git a/server/db/migrations/2.0.0-rc.2.js b/server/db/migrations/2.0.0-rc.2.js new file mode 100644 index 00000000..53e584b2 --- /dev/null +++ b/server/db/migrations/2.0.0-rc.2.js @@ -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') + }) +}