From 9c7523e3b171baf0d29ec0ec87f5d7c20eb318b6 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 25 Feb 2016 00:50:54 +0900 Subject: [PATCH] Use the new migration shortcuts in most of core's migrations --- ...2_24_000000_create_access_tokens_table.php | 23 ++++------ ...015_02_24_000000_create_api_keys_table.php | 17 +++----- .../2015_02_24_000000_create_config_table.php | 19 +++----- ..._02_24_000000_create_discussions_table.php | 39 ++++++++--------- ...02_24_000000_create_email_tokens_table.php | 23 ++++------ .../2015_02_24_000000_create_groups_table.php | 25 +++++------ ...2_24_000000_create_notifications_table.php | 35 +++++++-------- ...24_000000_create_password_tokens_table.php | 21 ++++----- ..._02_24_000000_create_permissions_table.php | 21 ++++----- .../2015_02_24_000000_create_posts_table.php | 2 + ..._000000_create_users_discussions_table.php | 25 +++++------ ...02_24_000000_create_users_groups_table.php | 21 ++++----- .../2015_02_24_000000_create_users_table.php | 43 ++++++++----------- ..._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 | 17 +------- ...10_07_130531_rename_config_to_settings.php | 12 +----- ...5_10_24_194000_add_ip_address_to_posts.php | 19 ++------ 18 files changed, 149 insertions(+), 255 deletions(-) diff --git a/framework/core/migrations/2015_02_24_000000_create_access_tokens_table.php b/framework/core/migrations/2015_02_24_000000_create_access_tokens_table.php index 220fd9ab3..7d1682f96 100644 --- a/framework/core/migrations/2015_02_24_000000_create_access_tokens_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_access_tokens_table.php @@ -8,20 +8,15 @@ * 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->create('access_tokens', function (Blueprint $table) { - $table->string('id', 100)->primary(); - $table->integer('user_id')->unsigned(); - $table->timestamp('created_at'); - $table->timestamp('expires_at'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('access_tokens'); +return Migration::createTable( + 'access_tokens', + function (Blueprint $table) { + $table->string('id', 100)->primary(); + $table->integer('user_id')->unsigned(); + $table->timestamp('created_at'); + $table->timestamp('expires_at'); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_api_keys_table.php b/framework/core/migrations/2015_02_24_000000_create_api_keys_table.php index f95417bde..00c53e240 100644 --- a/framework/core/migrations/2015_02_24_000000_create_api_keys_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_api_keys_table.php @@ -8,17 +8,12 @@ * 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->create('api_keys', function (Blueprint $table) { - $table->string('id', 100)->primary(); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('api_keys'); +return Migration::createTable( + 'api_keys', + function (Blueprint $table) { + $table->string('id', 100)->primary(); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_config_table.php b/framework/core/migrations/2015_02_24_000000_create_config_table.php index 935be0231..00a6af123 100644 --- a/framework/core/migrations/2015_02_24_000000_create_config_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_config_table.php @@ -8,18 +8,13 @@ * 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->create('config', function (Blueprint $table) { - $table->string('key', 100)->primary(); - $table->binary('value')->nullable(); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('config'); +return Migration::createTable( + 'config', + function (Blueprint $table) { + $table->string('key', 100)->primary(); + $table->binary('value')->nullable(); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_discussions_table.php b/framework/core/migrations/2015_02_24_000000_create_discussions_table.php index 4aebe8a53..f73d0e01d 100644 --- a/framework/core/migrations/2015_02_24_000000_create_discussions_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_discussions_table.php @@ -8,30 +8,25 @@ * 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->create('discussions', function (Blueprint $table) { - $table->increments('id'); - $table->string('title', 200); - $table->integer('comments_count')->unsigned()->default(0); - $table->integer('participants_count')->unsigned()->default(0); - $table->integer('number_index')->unsigned()->default(0); +return Migration::createTable( + 'discussions', + function (Blueprint $table) { + $table->increments('id'); + $table->string('title', 200); + $table->integer('comments_count')->unsigned()->default(0); + $table->integer('participants_count')->unsigned()->default(0); + $table->integer('number_index')->unsigned()->default(0); - $table->dateTime('start_time'); - $table->integer('start_user_id')->unsigned()->nullable(); - $table->integer('start_post_id')->unsigned()->nullable(); + $table->dateTime('start_time'); + $table->integer('start_user_id')->unsigned()->nullable(); + $table->integer('start_post_id')->unsigned()->nullable(); - $table->dateTime('last_time')->nullable(); - $table->integer('last_user_id')->unsigned()->nullable(); - $table->integer('last_post_id')->unsigned()->nullable(); - $table->integer('last_post_number')->unsigned()->nullable(); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('discussions'); + $table->dateTime('last_time')->nullable(); + $table->integer('last_user_id')->unsigned()->nullable(); + $table->integer('last_post_id')->unsigned()->nullable(); + $table->integer('last_post_number')->unsigned()->nullable(); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_email_tokens_table.php b/framework/core/migrations/2015_02_24_000000_create_email_tokens_table.php index e53491db9..85d229256 100644 --- a/framework/core/migrations/2015_02_24_000000_create_email_tokens_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_email_tokens_table.php @@ -8,20 +8,15 @@ * 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->create('email_tokens', function (Blueprint $table) { - $table->string('id', 100)->primary(); - $table->string('email', 150); - $table->integer('user_id')->unsigned(); - $table->timestamp('created_at'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('email_tokens'); +return Migration::createTable( + 'email_tokens', + function (Blueprint $table) { + $table->string('id', 100)->primary(); + $table->string('email', 150); + $table->integer('user_id')->unsigned(); + $table->timestamp('created_at'); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_groups_table.php b/framework/core/migrations/2015_02_24_000000_create_groups_table.php index 4fabd977c..9a75e43c6 100644 --- a/framework/core/migrations/2015_02_24_000000_create_groups_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_groups_table.php @@ -8,21 +8,16 @@ * 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->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(); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('groups'); +return Migration::createTable( + '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(); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_notifications_table.php b/framework/core/migrations/2015_02_24_000000_create_notifications_table.php index caf1c4e08..ba5c6331c 100644 --- a/framework/core/migrations/2015_02_24_000000_create_notifications_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_notifications_table.php @@ -8,26 +8,21 @@ * 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->create('notifications', function (Blueprint $table) { - $table->increments('id'); - $table->integer('user_id')->unsigned(); - $table->integer('sender_id')->unsigned()->nullable(); - $table->string('type', 100); - $table->string('subject_type', 200)->nullable(); - $table->integer('subject_id')->unsigned()->nullable(); - $table->binary('data')->nullable(); - $table->dateTime('time'); - $table->boolean('is_read')->default(0); - $table->boolean('is_deleted')->default(0); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('notifications'); +return Migration::createTable( + 'notifications', + function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned(); + $table->integer('sender_id')->unsigned()->nullable(); + $table->string('type', 100); + $table->string('subject_type', 200)->nullable(); + $table->integer('subject_id')->unsigned()->nullable(); + $table->binary('data')->nullable(); + $table->dateTime('time'); + $table->boolean('is_read')->default(0); + $table->boolean('is_deleted')->default(0); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_password_tokens_table.php b/framework/core/migrations/2015_02_24_000000_create_password_tokens_table.php index 094e36520..cd0e062ec 100644 --- a/framework/core/migrations/2015_02_24_000000_create_password_tokens_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_password_tokens_table.php @@ -8,19 +8,14 @@ * 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->create('password_tokens', function (Blueprint $table) { - $table->string('id', 100)->primary(); - $table->integer('user_id')->unsigned(); - $table->timestamp('created_at'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('password_tokens'); +return Migration::createTable( + 'password_tokens', + function (Blueprint $table) { + $table->string('id', 100)->primary(); + $table->integer('user_id')->unsigned(); + $table->timestamp('created_at'); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_permissions_table.php b/framework/core/migrations/2015_02_24_000000_create_permissions_table.php index ccd1d63b7..e9f814f38 100644 --- a/framework/core/migrations/2015_02_24_000000_create_permissions_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_permissions_table.php @@ -8,19 +8,14 @@ * 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->create('permissions', function (Blueprint $table) { - $table->integer('group_id')->unsigned(); - $table->string('permission', 100); - $table->primary(['group_id', 'permission']); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('permissions'); +return Migration::createTable( + 'permissions', + function (Blueprint $table) { + $table->integer('group_id')->unsigned(); + $table->string('permission', 100); + $table->primary(['group_id', 'permission']); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_posts_table.php b/framework/core/migrations/2015_02_24_000000_create_posts_table.php index 97bd61e66..422642976 100644 --- a/framework/core/migrations/2015_02_24_000000_create_posts_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_posts_table.php @@ -11,6 +11,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; +// We need a full custom migration here, because we need to add the fulltext +// index for the content with a raw SQL statement after creating the table. return [ 'up' => function (Builder $schema) { $schema->create('posts', function (Blueprint $table) { diff --git a/framework/core/migrations/2015_02_24_000000_create_users_discussions_table.php b/framework/core/migrations/2015_02_24_000000_create_users_discussions_table.php index cc579b05e..68863beb0 100644 --- a/framework/core/migrations/2015_02_24_000000_create_users_discussions_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_users_discussions_table.php @@ -8,21 +8,16 @@ * 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->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']); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('users_discussions'); +return Migration::createTable( + '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']); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_users_groups_table.php b/framework/core/migrations/2015_02_24_000000_create_users_groups_table.php index 64d2cb9b6..c10c5966f 100644 --- a/framework/core/migrations/2015_02_24_000000_create_users_groups_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_users_groups_table.php @@ -8,19 +8,14 @@ * 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->create('users_groups', function (Blueprint $table) { - $table->integer('user_id')->unsigned(); - $table->integer('group_id')->unsigned(); - $table->primary(['user_id', 'group_id']); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('users_groups'); +return Migration::createTable( + 'users_groups', + function (Blueprint $table) { + $table->integer('user_id')->unsigned(); + $table->integer('group_id')->unsigned(); + $table->primary(['user_id', 'group_id']); } -]; +); diff --git a/framework/core/migrations/2015_02_24_000000_create_users_table.php b/framework/core/migrations/2015_02_24_000000_create_users_table.php index 4edf78a5c..1ca6e7a5a 100644 --- a/framework/core/migrations/2015_02_24_000000_create_users_table.php +++ b/framework/core/migrations/2015_02_24_000000_create_users_table.php @@ -8,30 +8,25 @@ * 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->create('users', function (Blueprint $table) { - $table->increments('id'); - $table->string('username', 100)->unique(); - $table->string('email', 150)->unique(); - $table->boolean('is_activated')->default(0); - $table->string('password', 100); - $table->text('bio')->nullable(); - $table->string('avatar_path', 100)->nullable(); - $table->binary('preferences')->nullable(); - $table->dateTime('join_time')->nullable(); - $table->dateTime('last_seen_time')->nullable(); - $table->dateTime('read_time')->nullable(); - $table->dateTime('notification_read_time')->nullable(); - $table->integer('discussions_count')->unsigned()->default(0); - $table->integer('comments_count')->unsigned()->default(0); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('users'); +return Migration::createTable( + 'users', + function (Blueprint $table) { + $table->increments('id'); + $table->string('username', 100)->unique(); + $table->string('email', 150)->unique(); + $table->boolean('is_activated')->default(0); + $table->string('password', 100); + $table->text('bio')->nullable(); + $table->string('avatar_path', 100)->nullable(); + $table->binary('preferences')->nullable(); + $table->dateTime('join_time')->nullable(); + $table->dateTime('last_seen_time')->nullable(); + $table->dateTime('read_time')->nullable(); + $table->dateTime('notification_read_time')->nullable(); + $table->integer('discussions_count')->unsigned()->default(0); + $table->integer('comments_count')->unsigned()->default(0); } -]; +); diff --git a/framework/core/migrations/2015_09_15_000000_create_auth_tokens_table.php b/framework/core/migrations/2015_09_15_000000_create_auth_tokens_table.php index 6503723a6..2b78ab8f4 100644 --- a/framework/core/migrations/2015_09_15_000000_create_auth_tokens_table.php +++ b/framework/core/migrations/2015_09_15_000000_create_auth_tokens_table.php @@ -8,19 +8,14 @@ * 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->create('auth_tokens', function (Blueprint $table) { - $table->string('id', 100)->primary(); - $table->string('payload', 150); - $table->timestamp('created_at'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->drop('auth_tokens'); +return Migration::createTable( + 'auth_tokens', + function (Blueprint $table) { + $table->string('id', 100)->primary(); + $table->string('payload', 150); + $table->timestamp('created_at'); } -]; +); diff --git a/framework/core/migrations/2015_09_20_224327_add_hide_to_discussions.php b/framework/core/migrations/2015_09_20_224327_add_hide_to_discussions.php index 63669732a..357d95697 100644 --- a/framework/core/migrations/2015_09_20_224327_add_hide_to_discussions.php +++ b/framework/core/migrations/2015_09_20_224327_add_hide_to_discussions.php @@ -8,20 +8,9 @@ * file that was distributed with this source code. */ -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; +use Flarum\Database\Migration; -return [ - 'up' => function (Builder $schema) { - $schema->table('discussions', function (Blueprint $table) { - $table->dateTime('hide_time')->nullable(); - $table->integer('hide_user_id')->unsigned()->nullable(); - }); - }, - - 'down' => function (Builder $schema) { - $schema->table('discussions', function (Blueprint $table) { - $table->dropColumn(['hide_time', 'hide_user_id']); - }); - } -]; +return Migration::addColumns('discussions', [ + 'hide_time' => ['dateTime', 'nullable' => true], + 'hide_user_id' => ['integer', 'unsigned' => true, 'nullable' => true] +]); diff --git a/framework/core/migrations/2015_09_22_030432_rename_notification_read_time.php b/framework/core/migrations/2015_09_22_030432_rename_notification_read_time.php index 598db92e7..c6520a626 100644 --- a/framework/core/migrations/2015_09_22_030432_rename_notification_read_time.php +++ b/framework/core/migrations/2015_09_22_030432_rename_notification_read_time.php @@ -8,19 +8,6 @@ * file that was distributed with this source code. */ -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; +use Flarum\Database\Migration; -return [ - 'up' => function (Builder $schema) { - $schema->table('users', function (Blueprint $table) { - $table->renameColumn('notification_read_time', 'notifications_read_time'); - }); - }, - - 'down' => function (Builder $schema) { - $schema->table('users', function (Blueprint $table) { - $table->renameColumn('notifications_read_time', 'notification_read_time'); - }); - } -]; +return Migration::renameColumn('users', 'notification_read_time', 'notifications_read_time'); diff --git a/framework/core/migrations/2015_10_07_130531_rename_config_to_settings.php b/framework/core/migrations/2015_10_07_130531_rename_config_to_settings.php index 4d3683511..3c022668e 100644 --- a/framework/core/migrations/2015_10_07_130531_rename_config_to_settings.php +++ b/framework/core/migrations/2015_10_07_130531_rename_config_to_settings.php @@ -8,14 +8,6 @@ * file that was distributed with this source code. */ -use Illuminate\Database\Schema\Builder; +use Flarum\Database\Migration; -return [ - 'up' => function (Builder $schema) { - $schema->rename('config', 'settings'); - }, - - 'down' => function (Builder $schema) { - $schema->rename('settings', 'config'); - } -]; +return Migration::renameTable('config', 'settings'); diff --git a/framework/core/migrations/2015_10_24_194000_add_ip_address_to_posts.php b/framework/core/migrations/2015_10_24_194000_add_ip_address_to_posts.php index cc40a1143..ed24e8d4e 100644 --- a/framework/core/migrations/2015_10_24_194000_add_ip_address_to_posts.php +++ b/framework/core/migrations/2015_10_24_194000_add_ip_address_to_posts.php @@ -8,19 +8,8 @@ * file that was distributed with this source code. */ -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; +use Flarum\Database\Migration; -return [ - 'up' => function (Builder $schema) { - $schema->table('posts', function (Blueprint $table) { - $table->string('ip_address', 45)->nullable(); - }); - }, - - 'down' => function (Builder $schema) { - $schema->table('posts', function (Blueprint $table) { - $table->dropColumn(['ip_address']); - }); - } -]; +return Migration::addColumns('posts', [ + 'ip_address' => ['string', 'length' => 45, 'nullable' => true] +]);