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.
This commit is contained in:
Franz Liedke 2018-11-30 14:02:37 +01:00
parent d6632c061d
commit c23b7f33eb
5 changed files with 15 additions and 11 deletions

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});