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.
*/
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');
}
];
);

View File

@ -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();
}
];
);

View File

@ -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();
}
];
);

View File

@ -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();
}
];
);

View File

@ -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');
}
];
);

View File

@ -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();
}
];
);

View File

@ -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);
}
];
);

View File

@ -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');
}
];
);

View File

@ -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']);
}
];
);

View File

@ -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) {

View File

@ -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']);
}
];
);

View File

@ -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']);
}
];
);

View File

@ -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);
}
];
);

View File

@ -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');
}
];
);

View File

@ -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]
]);

View File

@ -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');

View File

@ -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');

View File

@ -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]
]);