From d08bb264b4d53df7fc2c233c5a823708816d485e Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 27 Nov 2018 22:34:26 +1030 Subject: [PATCH] Fix index names in migrations This can be reverted when we upgrade to Laravel 5.7. --- .../migrations/2015_10_19_061223_make_slug_unique.php | 11 ++++++++--- ...2018_06_27_085300_change_tags_add_foreign_keys.php | 9 +++++++-- ..._06_27_100200_change_tag_user_add_foreign_keys.php | 9 +++++++-- ...8_06_27_103100_add_discussion_tag_foreign_keys.php | 9 +++++++-- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/extensions/tags/migrations/2015_10_19_061223_make_slug_unique.php b/extensions/tags/migrations/2015_10_19_061223_make_slug_unique.php index 0ad0b76e5..a7c621486 100644 --- a/extensions/tags/migrations/2015_10_19_061223_make_slug_unique.php +++ b/extensions/tags/migrations/2015_10_19_061223_make_slug_unique.php @@ -9,21 +9,26 @@ * file that was distributed with this source code. */ +use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; return [ 'up' => function (Builder $schema) { - $schema->table('tags', function (Blueprint $table) { + $schema->table('tags', function (Blueprint $table) use ($schema) { $table->string('slug', 100)->change(); $table->unique('slug'); + + Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { - $schema->table('tags', function (Blueprint $table) { + $schema->table('tags', function (Blueprint $table) use ($schema) { $table->string('slug', 255)->change(); - $table->dropUnique('tags_slug_unique'); + $table->dropUnique(['slug']); + + Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/extensions/tags/migrations/2018_06_27_085300_change_tags_add_foreign_keys.php b/extensions/tags/migrations/2018_06_27_085300_change_tags_add_foreign_keys.php index d00ef7bf7..c79429045 100644 --- a/extensions/tags/migrations/2018_06_27_085300_change_tags_add_foreign_keys.php +++ b/extensions/tags/migrations/2018_06_27_085300_change_tags_add_foreign_keys.php @@ -9,6 +9,7 @@ * file that was distributed with this source code. */ +use Flarum\Database\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -30,16 +31,20 @@ return [ 'last_posted_discussion_id' => $select('id', 'discussions', 'last_posted_discussion_id'), ]); - $schema->table('tags', function (Blueprint $table) { + $schema->table('tags', function (Blueprint $table) use ($schema) { $table->foreign('parent_id')->references('id')->on('tags')->onDelete('set null'); $table->foreign('last_posted_user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('last_posted_discussion_id')->references('id')->on('discussions')->onDelete('set null'); + + Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { - $schema->table('tags', function (Blueprint $table) { + $schema->table('tags', function (Blueprint $table) use ($schema) { $table->dropForeign(['parent_id', 'last_posted_discussion_id', 'last_posted_user_id']); + + Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/extensions/tags/migrations/2018_06_27_100200_change_tag_user_add_foreign_keys.php b/extensions/tags/migrations/2018_06_27_100200_change_tag_user_add_foreign_keys.php index 5b3661d0f..ce2d3b225 100644 --- a/extensions/tags/migrations/2018_06_27_100200_change_tag_user_add_foreign_keys.php +++ b/extensions/tags/migrations/2018_06_27_100200_change_tag_user_add_foreign_keys.php @@ -9,6 +9,7 @@ * file that was distributed with this source code. */ +use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -26,15 +27,19 @@ return [ }) ->delete(); - $schema->table('tag_user', function (Blueprint $table) { + $schema->table('tag_user', function (Blueprint $table) use ($schema) { $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + + Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { - $schema->table('tag_user', function (Blueprint $table) { + $schema->table('tag_user', function (Blueprint $table) use ($schema) { $table->dropForeign(['tag_id', 'user_id']); + + Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/extensions/tags/migrations/2018_06_27_103100_add_discussion_tag_foreign_keys.php b/extensions/tags/migrations/2018_06_27_103100_add_discussion_tag_foreign_keys.php index 277462b2f..58687c5e7 100644 --- a/extensions/tags/migrations/2018_06_27_103100_add_discussion_tag_foreign_keys.php +++ b/extensions/tags/migrations/2018_06_27_103100_add_discussion_tag_foreign_keys.php @@ -9,6 +9,7 @@ * file that was distributed with this source code. */ +use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -26,15 +27,19 @@ return [ }) ->delete(); - $schema->table('discussion_tag', function (Blueprint $table) { + $schema->table('discussion_tag', function (Blueprint $table) use ($schema) { $table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade'); $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade'); + + Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { - $schema->table('discussion_tag', function (Blueprint $table) { + $schema->table('discussion_tag', function (Blueprint $table) use ($schema) { $table->dropForeign(['discussion_id', 'tag_id']); + + Migration::fixIndexNames($schema, $table); }); } ];