1
0
mirror of https://github.com/flarum/core.git synced 2025-07-18 23:31:17 +02:00

Use the new migration shortcuts in most of core's migrations

This commit is contained in:
Franz Liedke
2016-02-25 00:50:54 +09:00
parent 14042bedaf
commit 9c7523e3b1
18 changed files with 149 additions and 255 deletions

View File

@@ -8,20 +8,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'access_tokens',
$schema->create('access_tokens', function (Blueprint $table) { function (Blueprint $table) {
$table->string('id', 100)->primary(); $table->string('id', 100)->primary();
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
$table->timestamp('created_at'); $table->timestamp('created_at');
$table->timestamp('expires_at'); $table->timestamp('expires_at');
});
},
'down' => function (Builder $schema) {
$schema->drop('access_tokens');
} }
]; );

View File

@@ -8,17 +8,12 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'api_keys',
$schema->create('api_keys', function (Blueprint $table) { function (Blueprint $table) {
$table->string('id', 100)->primary(); $table->string('id', 100)->primary();
});
},
'down' => function (Builder $schema) {
$schema->drop('api_keys');
} }
]; );

View File

@@ -8,18 +8,13 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'config',
$schema->create('config', function (Blueprint $table) { function (Blueprint $table) {
$table->string('key', 100)->primary(); $table->string('key', 100)->primary();
$table->binary('value')->nullable(); $table->binary('value')->nullable();
});
},
'down' => function (Builder $schema) {
$schema->drop('config');
} }
]; );

View File

@@ -8,12 +8,12 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'discussions',
$schema->create('discussions', function (Blueprint $table) { function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->string('title', 200); $table->string('title', 200);
$table->integer('comments_count')->unsigned()->default(0); $table->integer('comments_count')->unsigned()->default(0);
@@ -28,10 +28,5 @@ return [
$table->integer('last_user_id')->unsigned()->nullable(); $table->integer('last_user_id')->unsigned()->nullable();
$table->integer('last_post_id')->unsigned()->nullable(); $table->integer('last_post_id')->unsigned()->nullable();
$table->integer('last_post_number')->unsigned()->nullable(); $table->integer('last_post_number')->unsigned()->nullable();
});
},
'down' => function (Builder $schema) {
$schema->drop('discussions');
} }
]; );

View File

@@ -8,20 +8,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'email_tokens',
$schema->create('email_tokens', function (Blueprint $table) { function (Blueprint $table) {
$table->string('id', 100)->primary(); $table->string('id', 100)->primary();
$table->string('email', 150); $table->string('email', 150);
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
$table->timestamp('created_at'); $table->timestamp('created_at');
});
},
'down' => function (Builder $schema) {
$schema->drop('email_tokens');
} }
]; );

View File

@@ -8,21 +8,16 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'groups',
$schema->create('groups', function (Blueprint $table) { function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->string('name_singular', 100); $table->string('name_singular', 100);
$table->string('name_plural', 100); $table->string('name_plural', 100);
$table->string('color', 20)->nullable(); $table->string('color', 20)->nullable();
$table->string('icon', 100)->nullable(); $table->string('icon', 100)->nullable();
});
},
'down' => function (Builder $schema) {
$schema->drop('groups');
} }
]; );

View File

@@ -8,12 +8,12 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'notifications',
$schema->create('notifications', function (Blueprint $table) { function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
$table->integer('sender_id')->unsigned()->nullable(); $table->integer('sender_id')->unsigned()->nullable();
@@ -24,10 +24,5 @@ return [
$table->dateTime('time'); $table->dateTime('time');
$table->boolean('is_read')->default(0); $table->boolean('is_read')->default(0);
$table->boolean('is_deleted')->default(0); $table->boolean('is_deleted')->default(0);
});
},
'down' => function (Builder $schema) {
$schema->drop('notifications');
} }
]; );

View File

@@ -8,19 +8,14 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'password_tokens',
$schema->create('password_tokens', function (Blueprint $table) { function (Blueprint $table) {
$table->string('id', 100)->primary(); $table->string('id', 100)->primary();
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
$table->timestamp('created_at'); $table->timestamp('created_at');
});
},
'down' => function (Builder $schema) {
$schema->drop('password_tokens');
} }
]; );

View File

@@ -8,19 +8,14 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'permissions',
$schema->create('permissions', function (Blueprint $table) { function (Blueprint $table) {
$table->integer('group_id')->unsigned(); $table->integer('group_id')->unsigned();
$table->string('permission', 100); $table->string('permission', 100);
$table->primary(['group_id', 'permission']); $table->primary(['group_id', 'permission']);
});
},
'down' => function (Builder $schema) {
$schema->drop('permissions');
} }
]; );

View File

@@ -11,6 +11,8 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder; 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 [ return [
'up' => function (Builder $schema) { 'up' => function (Builder $schema) {
$schema->create('posts', function (Blueprint $table) { $schema->create('posts', function (Blueprint $table) {

View File

@@ -8,21 +8,16 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'users_discussions',
$schema->create('users_discussions', function (Blueprint $table) { function (Blueprint $table) {
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
$table->integer('discussion_id')->unsigned(); $table->integer('discussion_id')->unsigned();
$table->dateTime('read_time')->nullable(); $table->dateTime('read_time')->nullable();
$table->integer('read_number')->unsigned()->nullable(); $table->integer('read_number')->unsigned()->nullable();
$table->primary(['user_id', 'discussion_id']); $table->primary(['user_id', 'discussion_id']);
});
},
'down' => function (Builder $schema) {
$schema->drop('users_discussions');
} }
]; );

View File

@@ -8,19 +8,14 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'users_groups',
$schema->create('users_groups', function (Blueprint $table) { function (Blueprint $table) {
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
$table->integer('group_id')->unsigned(); $table->integer('group_id')->unsigned();
$table->primary(['user_id', 'group_id']); $table->primary(['user_id', 'group_id']);
});
},
'down' => function (Builder $schema) {
$schema->drop('users_groups');
} }
]; );

View File

@@ -8,12 +8,12 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'users',
$schema->create('users', function (Blueprint $table) { function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->string('username', 100)->unique(); $table->string('username', 100)->unique();
$table->string('email', 150)->unique(); $table->string('email', 150)->unique();
@@ -28,10 +28,5 @@ return [
$table->dateTime('notification_read_time')->nullable(); $table->dateTime('notification_read_time')->nullable();
$table->integer('discussions_count')->unsigned()->default(0); $table->integer('discussions_count')->unsigned()->default(0);
$table->integer('comments_count')->unsigned()->default(0); $table->integer('comments_count')->unsigned()->default(0);
});
},
'down' => function (Builder $schema) {
$schema->drop('users');
} }
]; );

View File

@@ -8,19 +8,14 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [ return Migration::createTable(
'up' => function (Builder $schema) { 'auth_tokens',
$schema->create('auth_tokens', function (Blueprint $table) { function (Blueprint $table) {
$table->string('id', 100)->primary(); $table->string('id', 100)->primary();
$table->string('payload', 150); $table->string('payload', 150);
$table->timestamp('created_at'); $table->timestamp('created_at');
});
},
'down' => function (Builder $schema) {
$schema->drop('auth_tokens');
} }
]; );

View File

@@ -8,20 +8,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Illuminate\Database\Schema\Blueprint; use Flarum\Database\Migration;
use Illuminate\Database\Schema\Builder;
return [ return Migration::addColumns('discussions', [
'up' => function (Builder $schema) { 'hide_time' => ['dateTime', 'nullable' => true],
$schema->table('discussions', function (Blueprint $table) { 'hide_user_id' => ['integer', 'unsigned' => true, 'nullable' => true]
$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']);
});
}
];

View File

@@ -8,19 +8,6 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Illuminate\Database\Schema\Blueprint; use Flarum\Database\Migration;
use Illuminate\Database\Schema\Builder;
return [ return Migration::renameColumn('users', 'notification_read_time', 'notifications_read_time');
'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');
});
}
];

View File

@@ -8,14 +8,6 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Illuminate\Database\Schema\Builder; use Flarum\Database\Migration;
return [ return Migration::renameTable('config', 'settings');
'up' => function (Builder $schema) {
$schema->rename('config', 'settings');
},
'down' => function (Builder $schema) {
$schema->rename('settings', 'config');
}
];

View File

@@ -8,19 +8,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Illuminate\Database\Schema\Blueprint; use Flarum\Database\Migration;
use Illuminate\Database\Schema\Builder;
return [ return Migration::addColumns('posts', [
'up' => function (Builder $schema) { 'ip_address' => ['string', 'length' => 45, 'nullable' => true]
$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']);
});
}
];