From 9abdab3991c214158b909f3433f00fc8b553ded6 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 24 Sep 2018 15:58:40 +0100 Subject: [PATCH] Updated migration to convert MyISAM tables to InnoDB New bookshelves_books tables requires foreign constraints which error on MyISAM. For #1027 --- ..._08_04_115700_create_bookshelves_table.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/database/migrations/2018_08_04_115700_create_bookshelves_table.php b/database/migrations/2018_08_04_115700_create_bookshelves_table.php index e92b0edef..497730879 100644 --- a/database/migrations/2018_08_04_115700_create_bookshelves_table.php +++ b/database/migrations/2018_08_04_115700_create_bookshelves_table.php @@ -13,6 +13,28 @@ class CreateBookshelvesTable extends Migration */ public function up() { + + // Convert the existing entity tables to InnoDB. + // Wrapped in try-catch just in the event a different database system is used + // which does not support InnoDB but does support all required features + // like foreign key references. + try { + $prefix = DB::getTablePrefix(); + DB::statement("ALTER TABLE {$prefix}pages ENGINE = InnoDB;"); + DB::statement("ALTER TABLE {$prefix}chapters ENGINE = InnoDB;"); + DB::statement("ALTER TABLE {$prefix}books ENGINE = InnoDB;"); + } catch (Exception $exception) {} + + // Here we have table drops before the creations due to upgrade issues + // people were having due to the bookshelves_books table creation failing. + if (Schema::hasTable('bookshelves_books')) { + Schema::drop('bookshelves_books'); + } + + if (Schema::hasTable('bookshelves')) { + Schema::drop('bookshelves'); + } + Schema::create('bookshelves', function (Blueprint $table) { $table->increments('id'); $table->string('name', 200); @@ -35,12 +57,12 @@ class CreateBookshelvesTable extends Migration $table->integer('book_id')->unsigned(); $table->integer('order')->unsigned(); + $table->primary(['bookshelf_id', 'book_id']); + $table->foreign('bookshelf_id')->references('id')->on('bookshelves') ->onUpdate('cascade')->onDelete('cascade'); $table->foreign('book_id')->references('id')->on('books') ->onUpdate('cascade')->onDelete('cascade'); - - $table->primary(['bookshelf_id', 'book_id']); }); // Copy existing role permissions from Books