@@ -13,6 +13,28 @@ class CreateBookshelvesTable extends Migration
1313 */
1414 public function up ()
1515 {
16+
17+ // Convert the existing entity tables to InnoDB.
18+ // Wrapped in try-catch just in the event a different database system is used
19+ // which does not support InnoDB but does support all required features
20+ // like foreign key references.
21+ try {
22+ $ prefix = DB ::getTablePrefix ();
23+ DB ::statement ("ALTER TABLE {$ prefix }pages ENGINE = InnoDB; " );
24+ DB ::statement ("ALTER TABLE {$ prefix }chapters ENGINE = InnoDB; " );
25+ DB ::statement ("ALTER TABLE {$ prefix }books ENGINE = InnoDB; " );
26+ } catch (Exception $ exception ) {}
27+
28+ // Here we have table drops before the creations due to upgrade issues
29+ // people were having due to the bookshelves_books table creation failing.
30+ if (Schema::hasTable ('bookshelves_books ' )) {
31+ Schema::drop ('bookshelves_books ' );
32+ }
33+
34+ if (Schema::hasTable ('bookshelves ' )) {
35+ Schema::drop ('bookshelves ' );
36+ }
37+
1638 Schema::create ('bookshelves ' , function (Blueprint $ table ) {
1739 $ table ->increments ('id ' );
1840 $ table ->string ('name ' , 200 );
@@ -35,12 +57,12 @@ public function up()
3557 $ table ->integer ('book_id ' )->unsigned ();
3658 $ table ->integer ('order ' )->unsigned ();
3759
60+ $ table ->primary (['bookshelf_id ' , 'book_id ' ]);
61+
3862 $ table ->foreign ('bookshelf_id ' )->references ('id ' )->on ('bookshelves ' )
3963 ->onUpdate ('cascade ' )->onDelete ('cascade ' );
4064 $ table ->foreign ('book_id ' )->references ('id ' )->on ('books ' )
4165 ->onUpdate ('cascade ' )->onDelete ('cascade ' );
42-
43- $ table ->primary (['bookshelf_id ' , 'book_id ' ]);
4466 });
4567
4668 // Copy existing role permissions from Books
0 commit comments