From 51955504aa7b0c55e20ee72f09a299943bf1d0be Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 24 Feb 2016 22:23:49 +0900 Subject: [PATCH] Revamp migration structure They are now simply files that return an array of closures, for running the named "up" and "down" actions, respectively. Related to #732. --- ...2_24_000000_create_access_tokens_table.php | 21 ++++++---------- ...015_02_24_000000_create_api_keys_table.php | 21 ++++++---------- .../2015_02_24_000000_create_config_table.php | 21 ++++++---------- ..._02_24_000000_create_discussions_table.php | 21 ++++++---------- ...02_24_000000_create_email_tokens_table.php | 21 ++++++---------- .../2015_02_24_000000_create_groups_table.php | 21 ++++++---------- ...2_24_000000_create_notifications_table.php | 21 ++++++---------- ...24_000000_create_password_tokens_table.php | 21 ++++++---------- ..._02_24_000000_create_permissions_table.php | 21 ++++++---------- .../2015_02_24_000000_create_posts_table.php | 25 ++++++++----------- ..._000000_create_users_discussions_table.php | 21 ++++++---------- ...02_24_000000_create_users_groups_table.php | 21 ++++++---------- .../2015_02_24_000000_create_users_table.php | 21 ++++++---------- ..._09_15_000000_create_auth_tokens_table.php | 21 ++++++---------- ...5_09_20_224327_add_hide_to_discussions.php | 21 ++++++---------- ...2_030432_rename_notification_read_time.php | 21 ++++++---------- ...10_07_130531_rename_config_to_settings.php | 21 ++++++---------- ...5_10_24_194000_add_ip_address_to_posts.php | 21 ++++++---------- ...05_042721_change_access_tokens_columns.php | 21 ++++++---------- ...7_change_settings_value_column_to_text.php | 21 ++++++---------- ...6_02_04_095452_add_slug_to_discussions.php | 25 ++++++++----------- 21 files changed, 172 insertions(+), 277 deletions(-) diff --git a/migrations/2015_02_24_000000_create_access_tokens_table.php b/migrations/2015_02_24_000000_create_access_tokens_table.php index 00c941cc3..220fd9ab3 100644 --- a/migrations/2015_02_24_000000_create_access_tokens_table.php +++ b/migrations/2015_02_24_000000_create_access_tokens_table.php @@ -8,25 +8,20 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateAccessTokensTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('access_tokens', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('access_tokens', function (Blueprint $table) { $table->string('id', 100)->primary(); $table->integer('user_id')->unsigned(); $table->timestamp('created_at'); $table->timestamp('expires_at'); }); - } + }, - public function down() - { - $this->schema->drop('access_tokens'); + 'down' => function (Builder $schema) { + $schema->drop('access_tokens'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_api_keys_table.php b/migrations/2015_02_24_000000_create_api_keys_table.php index 6fb8a1f74..f95417bde 100644 --- a/migrations/2015_02_24_000000_create_api_keys_table.php +++ b/migrations/2015_02_24_000000_create_api_keys_table.php @@ -8,22 +8,17 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateApiKeysTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('api_keys', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('api_keys', function (Blueprint $table) { $table->string('id', 100)->primary(); }); - } + }, - public function down() - { - $this->schema->drop('api_keys'); + 'down' => function (Builder $schema) { + $schema->drop('api_keys'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_config_table.php b/migrations/2015_02_24_000000_create_config_table.php index 6b8fd3071..935be0231 100644 --- a/migrations/2015_02_24_000000_create_config_table.php +++ b/migrations/2015_02_24_000000_create_config_table.php @@ -8,23 +8,18 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateConfigTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('config', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('config', function (Blueprint $table) { $table->string('key', 100)->primary(); $table->binary('value')->nullable(); }); - } + }, - public function down() - { - $this->schema->drop('config'); + 'down' => function (Builder $schema) { + $schema->drop('config'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_discussions_table.php b/migrations/2015_02_24_000000_create_discussions_table.php index 1e8b7f964..4aebe8a53 100644 --- a/migrations/2015_02_24_000000_create_discussions_table.php +++ b/migrations/2015_02_24_000000_create_discussions_table.php @@ -8,16 +8,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateDiscussionsTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('discussions', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('discussions', function (Blueprint $table) { $table->increments('id'); $table->string('title', 200); $table->integer('comments_count')->unsigned()->default(0); @@ -33,10 +29,9 @@ class CreateDiscussionsTable extends AbstractMigration $table->integer('last_post_id')->unsigned()->nullable(); $table->integer('last_post_number')->unsigned()->nullable(); }); - } + }, - public function down() - { - $this->schema->drop('discussions'); + 'down' => function (Builder $schema) { + $schema->drop('discussions'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_email_tokens_table.php b/migrations/2015_02_24_000000_create_email_tokens_table.php index 652d7238b..e53491db9 100644 --- a/migrations/2015_02_24_000000_create_email_tokens_table.php +++ b/migrations/2015_02_24_000000_create_email_tokens_table.php @@ -8,25 +8,20 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateEmailTokensTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('email_tokens', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('email_tokens', function (Blueprint $table) { $table->string('id', 100)->primary(); $table->string('email', 150); $table->integer('user_id')->unsigned(); $table->timestamp('created_at'); }); - } + }, - public function down() - { - $this->schema->drop('email_tokens'); + 'down' => function (Builder $schema) { + $schema->drop('email_tokens'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_groups_table.php b/migrations/2015_02_24_000000_create_groups_table.php index 39ef03627..4fabd977c 100644 --- a/migrations/2015_02_24_000000_create_groups_table.php +++ b/migrations/2015_02_24_000000_create_groups_table.php @@ -8,26 +8,21 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateGroupsTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('groups', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('groups', function (Blueprint $table) { $table->increments('id'); $table->string('name_singular', 100); $table->string('name_plural', 100); $table->string('color', 20)->nullable(); $table->string('icon', 100)->nullable(); }); - } + }, - public function down() - { - $this->schema->drop('groups'); + 'down' => function (Builder $schema) { + $schema->drop('groups'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_notifications_table.php b/migrations/2015_02_24_000000_create_notifications_table.php index b81b8cb61..caf1c4e08 100644 --- a/migrations/2015_02_24_000000_create_notifications_table.php +++ b/migrations/2015_02_24_000000_create_notifications_table.php @@ -8,16 +8,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateNotificationsTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('notifications', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('notifications', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id')->unsigned(); $table->integer('sender_id')->unsigned()->nullable(); @@ -29,10 +25,9 @@ class CreateNotificationsTable extends AbstractMigration $table->boolean('is_read')->default(0); $table->boolean('is_deleted')->default(0); }); - } + }, - public function down() - { - $this->schema->drop('notifications'); + 'down' => function (Builder $schema) { + $schema->drop('notifications'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_password_tokens_table.php b/migrations/2015_02_24_000000_create_password_tokens_table.php index 6c3ee5fdd..094e36520 100644 --- a/migrations/2015_02_24_000000_create_password_tokens_table.php +++ b/migrations/2015_02_24_000000_create_password_tokens_table.php @@ -8,24 +8,19 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreatePasswordTokensTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('password_tokens', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('password_tokens', function (Blueprint $table) { $table->string('id', 100)->primary(); $table->integer('user_id')->unsigned(); $table->timestamp('created_at'); }); - } + }, - public function down() - { - $this->schema->drop('password_tokens'); + 'down' => function (Builder $schema) { + $schema->drop('password_tokens'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_permissions_table.php b/migrations/2015_02_24_000000_create_permissions_table.php index b9b691846..ccd1d63b7 100644 --- a/migrations/2015_02_24_000000_create_permissions_table.php +++ b/migrations/2015_02_24_000000_create_permissions_table.php @@ -8,24 +8,19 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreatePermissionsTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('permissions', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('permissions', function (Blueprint $table) { $table->integer('group_id')->unsigned(); $table->string('permission', 100); $table->primary(['group_id', 'permission']); }); - } + }, - public function down() - { - $this->schema->drop('permissions'); + 'down' => function (Builder $schema) { + $schema->drop('permissions'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_posts_table.php b/migrations/2015_02_24_000000_create_posts_table.php index 16c78573a..97bd61e66 100644 --- a/migrations/2015_02_24_000000_create_posts_table.php +++ b/migrations/2015_02_24_000000_create_posts_table.php @@ -8,16 +8,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreatePostsTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('posts', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('posts', function (Blueprint $table) { $table->increments('id'); $table->integer('discussion_id')->unsigned(); $table->integer('number')->unsigned()->nullable(); @@ -37,12 +33,11 @@ class CreatePostsTable extends AbstractMigration $table->engine = 'MyISAM'; }); - $prefix = $this->schema->getConnection()->getTablePrefix(); - $this->schema->getConnection()->statement('ALTER TABLE '.$prefix.'posts ADD FULLTEXT content (content)'); - } + $prefix = $schema->getConnection()->getTablePrefix(); + $schema->getConnection()->statement('ALTER TABLE '.$prefix.'posts ADD FULLTEXT content (content)'); + }, - public function down() - { - $this->schema->drop('posts'); + 'down' => function (Builder $schema) { + $schema->drop('posts'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_users_discussions_table.php b/migrations/2015_02_24_000000_create_users_discussions_table.php index 6e5c0a547..cc579b05e 100644 --- a/migrations/2015_02_24_000000_create_users_discussions_table.php +++ b/migrations/2015_02_24_000000_create_users_discussions_table.php @@ -8,26 +8,21 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateUsersDiscussionsTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('users_discussions', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('users_discussions', function (Blueprint $table) { $table->integer('user_id')->unsigned(); $table->integer('discussion_id')->unsigned(); $table->dateTime('read_time')->nullable(); $table->integer('read_number')->unsigned()->nullable(); $table->primary(['user_id', 'discussion_id']); }); - } + }, - public function down() - { - $this->schema->drop('users_discussions'); + 'down' => function (Builder $schema) { + $schema->drop('users_discussions'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_users_groups_table.php b/migrations/2015_02_24_000000_create_users_groups_table.php index 4b39efbdb..64d2cb9b6 100644 --- a/migrations/2015_02_24_000000_create_users_groups_table.php +++ b/migrations/2015_02_24_000000_create_users_groups_table.php @@ -8,24 +8,19 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateUsersGroupsTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('users_groups', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('users_groups', function (Blueprint $table) { $table->integer('user_id')->unsigned(); $table->integer('group_id')->unsigned(); $table->primary(['user_id', 'group_id']); }); - } + }, - public function down() - { - $this->schema->drop('users_groups'); + 'down' => function (Builder $schema) { + $schema->drop('users_groups'); } -} +]; diff --git a/migrations/2015_02_24_000000_create_users_table.php b/migrations/2015_02_24_000000_create_users_table.php index cb1dfd28d..4edf78a5c 100644 --- a/migrations/2015_02_24_000000_create_users_table.php +++ b/migrations/2015_02_24_000000_create_users_table.php @@ -8,16 +8,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateUsersTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('users', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('users', function (Blueprint $table) { $table->increments('id'); $table->string('username', 100)->unique(); $table->string('email', 150)->unique(); @@ -33,10 +29,9 @@ class CreateUsersTable extends AbstractMigration $table->integer('discussions_count')->unsigned()->default(0); $table->integer('comments_count')->unsigned()->default(0); }); - } + }, - public function down() - { - $this->schema->drop('users'); + 'down' => function (Builder $schema) { + $schema->drop('users'); } -} +]; diff --git a/migrations/2015_09_15_000000_create_auth_tokens_table.php b/migrations/2015_09_15_000000_create_auth_tokens_table.php index a98a58679..6503723a6 100644 --- a/migrations/2015_09_15_000000_create_auth_tokens_table.php +++ b/migrations/2015_09_15_000000_create_auth_tokens_table.php @@ -8,24 +8,19 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class CreateAuthTokensTable extends AbstractMigration -{ - public function up() - { - $this->schema->create('auth_tokens', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->create('auth_tokens', function (Blueprint $table) { $table->string('id', 100)->primary(); $table->string('payload', 150); $table->timestamp('created_at'); }); - } + }, - public function down() - { - $this->schema->drop('auth_tokens'); + 'down' => function (Builder $schema) { + $schema->drop('auth_tokens'); } -} +]; diff --git a/migrations/2015_09_20_224327_add_hide_to_discussions.php b/migrations/2015_09_20_224327_add_hide_to_discussions.php index ba118d8a9..63669732a 100644 --- a/migrations/2015_09_20_224327_add_hide_to_discussions.php +++ b/migrations/2015_09_20_224327_add_hide_to_discussions.php @@ -8,25 +8,20 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class AddHideToDiscussions extends AbstractMigration -{ - public function up() - { - $this->schema->table('discussions', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->table('discussions', function (Blueprint $table) { $table->dateTime('hide_time')->nullable(); $table->integer('hide_user_id')->unsigned()->nullable(); }); - } + }, - public function down() - { - $this->schema->table('discussions', function (Blueprint $table) { + 'down' => function (Builder $schema) { + $schema->table('discussions', function (Blueprint $table) { $table->dropColumn(['hide_time', 'hide_user_id']); }); } -} +]; diff --git a/migrations/2015_09_22_030432_rename_notification_read_time.php b/migrations/2015_09_22_030432_rename_notification_read_time.php index 020f351a0..598db92e7 100644 --- a/migrations/2015_09_22_030432_rename_notification_read_time.php +++ b/migrations/2015_09_22_030432_rename_notification_read_time.php @@ -8,24 +8,19 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class RenameNotificationReadTime extends AbstractMigration -{ - public function up() - { - $this->schema->table('users', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { $table->renameColumn('notification_read_time', 'notifications_read_time'); }); - } + }, - public function down() - { - $this->schema->table('users', function (Blueprint $table) { + 'down' => function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { $table->renameColumn('notifications_read_time', 'notification_read_time'); }); } -} +]; diff --git a/migrations/2015_10_07_130531_rename_config_to_settings.php b/migrations/2015_10_07_130531_rename_config_to_settings.php index 4a1466c5a..4d3683511 100644 --- a/migrations/2015_10_07_130531_rename_config_to_settings.php +++ b/migrations/2015_10_07_130531_rename_config_to_settings.php @@ -8,19 +8,14 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; +use Illuminate\Database\Schema\Builder; -use Flarum\Database\AbstractMigration; +return [ + 'up' => function (Builder $schema) { + $schema->rename('config', 'settings'); + }, -class RenameConfigToSettings extends AbstractMigration -{ - public function up() - { - $this->schema->rename('config', 'settings'); + 'down' => function (Builder $schema) { + $schema->rename('settings', 'config'); } - - public function down() - { - $this->schema->rename('settings', 'config'); - } -} +]; diff --git a/migrations/2015_10_24_194000_add_ip_address_to_posts.php b/migrations/2015_10_24_194000_add_ip_address_to_posts.php index 2c8b2f2bd..cc40a1143 100644 --- a/migrations/2015_10_24_194000_add_ip_address_to_posts.php +++ b/migrations/2015_10_24_194000_add_ip_address_to_posts.php @@ -8,24 +8,19 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class AddIpAddressToPosts extends AbstractMigration -{ - public function up() - { - $this->schema->table('posts', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->table('posts', function (Blueprint $table) { $table->string('ip_address', 45)->nullable(); }); - } + }, - public function down() - { - $this->schema->table('posts', function (Blueprint $table) { + 'down' => function (Builder $schema) { + $schema->table('posts', function (Blueprint $table) { $table->dropColumn(['ip_address']); }); } -} +]; diff --git a/migrations/2015_12_05_042721_change_access_tokens_columns.php b/migrations/2015_12_05_042721_change_access_tokens_columns.php index 5d94c911b..e3f489320 100644 --- a/migrations/2015_12_05_042721_change_access_tokens_columns.php +++ b/migrations/2015_12_05_042721_change_access_tokens_columns.php @@ -1,26 +1,21 @@ schema->table('access_tokens', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->table('access_tokens', function (Blueprint $table) { $table->string('id', 40)->change(); $table->dropColumn('created_at'); $table->dropColumn('expires_at'); $table->integer('last_activity'); $table->integer('lifetime'); }); - } + }, - public function down() - { - $this->schema->table('access_tokens', function (Blueprint $table) { + 'down' => function (Builder $schema) { + $schema->table('access_tokens', function (Blueprint $table) { $table->string('id', 100)->change(); $table->dropColumn('last_activity'); $table->dropColumn('lifetime'); @@ -28,4 +23,4 @@ class ChangeAccessTokensColumns extends AbstractMigration $table->timestamp('expires_at'); }); } -} +]; diff --git a/migrations/2015_12_17_194247_change_settings_value_column_to_text.php b/migrations/2015_12_17_194247_change_settings_value_column_to_text.php index 85c603d27..402e43bca 100644 --- a/migrations/2015_12_17_194247_change_settings_value_column_to_text.php +++ b/migrations/2015_12_17_194247_change_settings_value_column_to_text.php @@ -1,23 +1,18 @@ schema->table('settings', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->table('settings', function (Blueprint $table) { $table->text('value')->change(); }); - } + }, - public function down() - { - $this->schema->table('settings', function (Blueprint $table) { + 'down' => function (Builder $schema) { + $schema->table('settings', function (Blueprint $table) { $table->binary('value')->change(); }); } -} +]; diff --git a/migrations/2016_02_04_095452_add_slug_to_discussions.php b/migrations/2016_02_04_095452_add_slug_to_discussions.php index abcd828ff..a6ddd8459 100644 --- a/migrations/2016_02_04_095452_add_slug_to_discussions.php +++ b/migrations/2016_02_04_095452_add_slug_to_discussions.php @@ -8,34 +8,29 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Migration; - -use Flarum\Database\AbstractMigration; use Flarum\Util\Str; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; -class AddSlugToDiscussions extends AbstractMigration -{ - public function up() - { - $this->schema->table('discussions', function (Blueprint $table) { +return [ + 'up' => function (Builder $schema) { + $schema->table('discussions', function (Blueprint $table) { $table->string('slug'); }); // Store slugs for existing discussions - $this->schema->getConnection()->table('discussions')->chunk(100, function ($discussions) { + $schema->getConnection()->table('discussions')->chunk(100, function ($discussions) use ($schema) { foreach ($discussions as $discussion) { - $this->schema->getConnection()->table('discussions')->where('id', $discussion->id)->update([ + $schema->getConnection()->table('discussions')->where('id', $discussion->id)->update([ 'slug' => Str::slug($discussion->title) ]); } }); - } + }, - public function down() - { - $this->schema->table('discussions', function (Blueprint $table) { + 'down' => function (Builder $schema) { + $schema->table('discussions', function (Blueprint $table) { $table->dropColumn('slug'); }); } -} +];