From d56ea1ef07a7c1948e0f7ac6b1e737f049c1be09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Tue, 15 Jan 2019 20:39:38 +0100 Subject: [PATCH] reverts #41688c7 --- ..._change_access_tokens_add_foreign_keys.php | 5 ---- ...8_01_11_095000_change_api_keys_columns.php | 17 +++--------- ...00_change_discussions_add_foreign_keys.php | 5 ---- ...hange_discussion_user_add_foreign_keys.php | 5 ---- ...0_change_email_tokens_add_foreign_keys.php | 5 ---- ...ange_group_permission_add_foreign_keys.php | 5 ---- ...700_change_group_user_add_foreign_keys.php | 5 ---- ..._change_notifications_add_foreign_keys.php | 5 ---- ...hange_password_tokens_add_foreign_keys.php | 5 ---- ...8_135100_change_posts_add_foreign_keys.php | 5 ---- .../2018_09_15_041340_add_users_indicies.php | 5 ---- ..._09_15_041828_add_discussions_indicies.php | 5 ---- ...09_15_043337_add_notifications_indices.php | 5 ---- .../2018_09_15_043621_add_posts_indices.php | 5 ---- framework/core/src/Database/Migration.php | 27 ------------------- 15 files changed, 4 insertions(+), 105 deletions(-) diff --git a/framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php b/framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php index 31a7bf073..7ed9921ce 100644 --- a/framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_11_094000_change_access_tokens_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -26,16 +25,12 @@ return [ $schema->table('access_tokens', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { $schema->table('access_tokens', function (Blueprint $table) use ($schema) { $table->dropForeign(['user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/framework/core/migrations/2018_01_11_095000_change_api_keys_columns.php b/framework/core/migrations/2018_01_11_095000_change_api_keys_columns.php index 6f2cc0a2e..eaa6246b4 100644 --- a/framework/core/migrations/2018_01_11_095000_change_api_keys_columns.php +++ b/framework/core/migrations/2018_01_11_095000_change_api_keys_columns.php @@ -9,21 +9,18 @@ * 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('api_keys', function (Blueprint $table) use ($schema) { + $schema->table('api_keys', function (Blueprint $table) { $table->dropPrimary(['id']); $table->renameColumn('id', 'key'); $table->unique('key'); - - Migration::fixIndexNames($schema, $table); }); - $schema->table('api_keys', function (Blueprint $table) use ($schema) { + $schema->table('api_keys', function (Blueprint $table) { $table->increments('id'); $table->string('allowed_ips')->nullable(); $table->string('scopes')->nullable(); @@ -32,25 +29,19 @@ return [ $table->dateTime('last_activity_at')->nullable(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { - $schema->table('api_keys', function (Blueprint $table) use ($schema) { + $schema->table('api_keys', function (Blueprint $table) { $table->dropForeign(['user_id']); $table->dropColumn('id', 'allowed_ips', 'user_id', 'scopes', 'created_at'); - - Migration::fixIndexNames($schema, $table); }); - $schema->table('api_keys', function (Blueprint $table) use ($schema) { + $schema->table('api_keys', function (Blueprint $table) { $table->dropUnique(['key']); $table->renameColumn('key', 'id'); $table->primary('id'); - - Migration::fixIndexNames($schema, $table); }); } ]; 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 e71e11680..4c8b68a3d 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 @@ -9,7 +9,6 @@ * 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; @@ -40,8 +39,6 @@ return [ $table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('first_post_id')->references('id')->on('posts')->onDelete('set null'); $table->foreign('last_post_id')->references('id')->on('posts')->onDelete('set null'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -52,8 +49,6 @@ return [ $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 f83c196f4..fdbfc22c4 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 @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -30,8 +29,6 @@ return [ $schema->table('discussion_user', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -39,8 +36,6 @@ return [ $schema->table('discussion_user', function (Blueprint $table) use ($schema) { $table->dropForeign(['user_id']); $table->dropForeign(['discussion_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php b/framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php index 943870e97..7d3053d04 100644 --- a/framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_15_072700_change_email_tokens_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -26,16 +25,12 @@ return [ $schema->table('email_tokens', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { $schema->table('email_tokens', function (Blueprint $table) use ($schema) { $table->dropForeign(['user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php b/framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php index 0952bb7b0..b24fc8acb 100644 --- a/framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_130500_change_group_permission_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -26,16 +25,12 @@ return [ $schema->table('group_permission', function (Blueprint $table) use ($schema) { $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { $schema->table('group_permission', function (Blueprint $table) use ($schema) { $table->dropForeign(['group_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 aa7b8785a..5a9bbdb34 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 @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -30,8 +29,6 @@ return [ $schema->table('group_user', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -39,8 +36,6 @@ return [ $schema->table('group_user', function (Blueprint $table) use ($schema) { $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 043d7e4c6..3f1f18f98 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 @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -34,8 +33,6 @@ return [ $schema->table('notifications', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('from_user_id')->references('id')->on('users')->onDelete('set null'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -43,8 +40,6 @@ return [ $schema->table('notifications', function (Blueprint $table) use ($schema) { $table->dropForeign(['user_id']); $table->dropForeign(['from_user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php b/framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php index 8d21b9cf3..6004e4049 100644 --- a/framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php +++ b/framework/core/migrations/2018_01_18_134500_change_password_tokens_add_foreign_keys.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -26,16 +25,12 @@ return [ $schema->table('password_tokens', function (Blueprint $table) use ($schema) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { $schema->table('password_tokens', function (Blueprint $table) use ($schema) { $table->dropForeign(['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 2a6d0e771..1cc9d84e2 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 @@ -9,7 +9,6 @@ * 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; @@ -36,8 +35,6 @@ return [ $table->foreign('user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('edited_user_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -47,8 +44,6 @@ return [ $table->dropForeign(['discussion_id']); $table->dropForeign(['edited_user_id']); $table->dropForeign(['hidden_user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/framework/core/migrations/2018_09_15_041340_add_users_indicies.php b/framework/core/migrations/2018_09_15_041340_add_users_indicies.php index 263198af9..c1ad4c373 100644 --- a/framework/core/migrations/2018_09_15_041340_add_users_indicies.php +++ b/framework/core/migrations/2018_09_15_041340_add_users_indicies.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -20,8 +19,6 @@ return [ $table->index('last_seen_at'); $table->index('discussion_count'); $table->index('comment_count'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -31,8 +28,6 @@ return [ $table->dropIndex(['last_seen_at']); $table->dropIndex(['discussion_count']); $table->dropIndex(['comment_count']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/framework/core/migrations/2018_09_15_041828_add_discussions_indicies.php b/framework/core/migrations/2018_09_15_041828_add_discussions_indicies.php index eb73350ba..04e47415c 100644 --- a/framework/core/migrations/2018_09_15_041828_add_discussions_indicies.php +++ b/framework/core/migrations/2018_09_15_041828_add_discussions_indicies.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -23,8 +22,6 @@ return [ $table->index('comment_count'); $table->index('participant_count'); $table->index('hidden_at'); - - Migration::fixIndexNames($schema, $table); }); }, @@ -37,8 +34,6 @@ return [ $table->dropIndex(['comment_count']); $table->dropIndex(['participant_count']); $table->dropIndex(['hidden_at']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/framework/core/migrations/2018_09_15_043337_add_notifications_indices.php b/framework/core/migrations/2018_09_15_043337_add_notifications_indices.php index 78f123ab2..8aee5d098 100644 --- a/framework/core/migrations/2018_09_15_043337_add_notifications_indices.php +++ b/framework/core/migrations/2018_09_15_043337_add_notifications_indices.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -17,16 +16,12 @@ return [ 'up' => function (Builder $schema) { $schema->table('notifications', function (Blueprint $table) use ($schema) { $table->index('user_id'); - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) { $schema->table('notifications', function (Blueprint $table) use ($schema) { $table->dropIndex(['user_id']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/framework/core/migrations/2018_09_15_043621_add_posts_indices.php b/framework/core/migrations/2018_09_15_043621_add_posts_indices.php index 419d52a4c..6e67c197d 100644 --- a/framework/core/migrations/2018_09_15_043621_add_posts_indices.php +++ b/framework/core/migrations/2018_09_15_043621_add_posts_indices.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; @@ -19,8 +18,6 @@ return [ $table->index(['discussion_id', 'number']); $table->index(['discussion_id', 'created_at']); $table->index(['user_id', 'created_at']); - - Migration::fixIndexNames($schema, $table); }); }, @@ -29,8 +26,6 @@ return [ $table->dropIndex(['discussion_id', 'number']); $table->dropIndex(['discussion_id', 'created_at']); $table->dropIndex(['user_id', 'created_at']); - - Migration::fixIndexNames($schema, $table); }); } ]; diff --git a/framework/core/src/Database/Migration.php b/framework/core/src/Database/Migration.php index 6226bd913..6af42bfdf 100644 --- a/framework/core/src/Database/Migration.php +++ b/framework/core/src/Database/Migration.php @@ -31,8 +31,6 @@ abstract class Migration 'up' => function (Builder $schema) use ($name, $definition) { $schema->create($name, function (Blueprint $table) use ($schema, $definition) { $definition($table); - - static::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) use ($name) { @@ -68,8 +66,6 @@ abstract class Migration $type = array_shift($options); $table->addColumn($type, $columnName, $options); } - - Migration::fixIndexNames($schema, $table); }); }, 'down' => function (Builder $schema) use ($tableName, $columnDefinitions) { @@ -193,27 +189,4 @@ abstract class Migration } ]; } - - /** - * Add a prefix to index names on the given table blueprint. - * - * Laravel 5.5 doesn't automatically add the table prefix to index - * names, but this has been fixed in 5.7. We will manually fix the - * names for now, and we can remove this when we upgrade to 5.7. - */ - public static function fixIndexNames(Builder $schema, Blueprint $table) - { - $indexCommands = [ - 'unique', 'index', 'spatialIndex', 'foreign', - 'dropUnique', 'dropIndex', 'dropSpatialIndex', 'dropForeign' - ]; - - $prefix = $schema->getConnection()->getTablePrefix(); - - foreach ($table->getCommands() as $command) { - if (in_array($command->name, $indexCommands)) { - $command->index = $prefix.$command->index; - } - } - } }