From c23b7f33eb4bbf860de5e53501c9d72a29ee68ae Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 30 Nov 2018 14:02:37 +0100 Subject: [PATCH] Migrations: Fix dropping foreign keys Passing an array to dropForeign does not mean dropping multiple indices, but rather dropping a key on multiple tables. Passing a string means that this string will be interpreted as index name, not as name of the indexed column. Passing an array with one string is therefore correct, in order to benefit from automatic index name generation. --- ..._01_11_155300_change_discussions_add_foreign_keys.php | 9 +++++---- ...15_071900_change_discussion_user_add_foreign_keys.php | 3 ++- ...8_01_18_130700_change_group_user_add_foreign_keys.php | 3 ++- ...1_18_133100_change_notifications_add_foreign_keys.php | 3 ++- .../2018_01_18_135100_change_posts_add_foreign_keys.php | 8 ++++---- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php b/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php index 39d8d8e5d..e71e11680 100644 --- a/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_11_155300_change_discussions_add_foreign_keys.php @@ -47,10 +47,11 @@ return [ 'down' => function (Builder $schema) { $schema->table('discussions', function (Blueprint $table) use ($schema) { - $table->dropForeign([ - 'user_id', 'last_posted_user_id', 'hidden_user_id', - 'first_post_id', 'last_post_id' - ]); + $table->dropForeign(['user_id']); + $table->dropForeign(['last_posted_user_id']); + $table->dropForeign(['hidden_user_id']); + $table->dropForeign(['first_post_id']); + $table->dropForeign(['last_post_id']); Migration::fixIndexNames($schema, $table); }); diff --git a/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php b/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php index 1a89deb05..f83c196f4 100644 --- a/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_15_071900_change_discussion_user_add_foreign_keys.php @@ -37,7 +37,8 @@ return [ 'down' => function (Builder $schema) { $schema->table('discussion_user', function (Blueprint $table) use ($schema) { - $table->dropForeign(['user_id', 'discussion_id']); + $table->dropForeign(['user_id']); + $table->dropForeign(['discussion_id']); Migration::fixIndexNames($schema, $table); }); diff --git a/framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php b/framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php index 0bf369ae5..aa7b8785a 100644 --- a/framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_130700_change_group_user_add_foreign_keys.php @@ -37,7 +37,8 @@ return [ 'down' => function (Builder $schema) { $schema->table('group_user', function (Blueprint $table) use ($schema) { - $table->dropForeign(['user_id', 'group_id']); + $table->dropForeign(['user_id']); + $table->dropForeign(['group_id']); Migration::fixIndexNames($schema, $table); }); diff --git a/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php b/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php index 0626646eb..043d7e4c6 100644 --- a/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_133100_change_notifications_add_foreign_keys.php @@ -41,7 +41,8 @@ return [ 'down' => function (Builder $schema) { $schema->table('notifications', function (Blueprint $table) use ($schema) { - $table->dropForeign(['user_id', 'from_user_id']); + $table->dropForeign(['user_id']); + $table->dropForeign(['from_user_id']); Migration::fixIndexNames($schema, $table); }); diff --git a/framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php b/framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php index 5ef5d2a6e..2a6d0e771 100644 --- a/framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_135100_change_posts_add_foreign_keys.php @@ -43,10 +43,10 @@ return [ 'down' => function (Builder $schema) { $schema->table('posts', function (Blueprint $table) use ($schema) { - $table->dropForeign([ - 'user_id', 'discussion_id', - 'edited_user_id', 'hidden_user_id' - ]); + $table->dropForeign(['user_id']); + $table->dropForeign(['discussion_id']); + $table->dropForeign(['edited_user_id']); + $table->dropForeign(['hidden_user_id']); Migration::fixIndexNames($schema, $table); });