Skip to content

Commit

Permalink
Migrations: Fix dropping foreign keys
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
franzliedke committed Nov 30, 2018
1 parent fb6b51b commit 57d5846
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@

'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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

'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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

'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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

'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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@

'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);
});
Expand Down

0 comments on commit 57d5846

Please sign in to comment.