mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 03:32:49 +08:00
Use dependency injection in migrations
This commit is contained in:
parent
9762e20be1
commit
7b07e02e75
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateAccessTokensTable extends Migration
|
||||
|
@ -13,7 +13,7 @@ class CreateAccessTokensTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('access_tokens', function (Blueprint $table) {
|
||||
$this->schema->create('access_tokens', function (Blueprint $table) {
|
||||
$table->string('id', 100)->primary();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->timestamp('created_at');
|
||||
|
@ -28,6 +28,6 @@ class CreateAccessTokensTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('access_tokens');
|
||||
$this->schema->drop('access_tokens');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateActivityTable extends Migration
|
||||
|
@ -14,7 +14,7 @@ class CreateActivityTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('activity', function (Blueprint $table) {
|
||||
$this->schema->create('activity', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('type', 100);
|
||||
|
@ -31,6 +31,6 @@ class CreateActivityTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('activity');
|
||||
$this->schema->drop('activity');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateConfigTable extends Migration
|
||||
|
@ -14,7 +14,7 @@ class CreateConfigTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('config', function (Blueprint $table) {
|
||||
$this->schema->create('config', function (Blueprint $table) {
|
||||
|
||||
$table->string('key', 100)->primary();
|
||||
$table->binary('value')->nullable();
|
||||
|
@ -28,6 +28,6 @@ class CreateConfigTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('config');
|
||||
$this->schema->drop('config');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateDiscussionsTable extends Migration
|
||||
|
@ -14,7 +14,7 @@ class CreateDiscussionsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('discussions', function (Blueprint $table) {
|
||||
$this->schema->create('discussions', function (Blueprint $table) {
|
||||
|
||||
$table->increments('id');
|
||||
$table->string('title', 200);
|
||||
|
@ -40,6 +40,6 @@ class CreateDiscussionsTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('discussions');
|
||||
$this->schema->drop('discussions');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateEmailTokensTable extends Migration
|
||||
|
@ -13,7 +13,7 @@ class CreateEmailTokensTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('email_tokens', function (Blueprint $table) {
|
||||
$this->schema->create('email_tokens', function (Blueprint $table) {
|
||||
$table->string('id', 100)->primary();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('email', 150);
|
||||
|
@ -28,6 +28,6 @@ class CreateEmailTokensTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('email_tokens');
|
||||
$this->schema->drop('email_tokens');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateGroupsTable extends Migration
|
||||
|
@ -13,7 +13,7 @@ class CreateGroupsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('groups', function (Blueprint $table) {
|
||||
$this->schema->create('groups', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name_singular', 100);
|
||||
$table->string('name_plural', 100);
|
||||
|
@ -29,6 +29,6 @@ class CreateGroupsTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('groups');
|
||||
$this->schema->drop('groups');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateNotificationsTable extends Migration
|
||||
|
@ -14,7 +14,7 @@ class CreateNotificationsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('notifications', function (Blueprint $table) {
|
||||
$this->schema->create('notifications', function (Blueprint $table) {
|
||||
|
||||
$table->increments('id');
|
||||
$table->integer('user_id')->unsigned();
|
||||
|
@ -36,6 +36,6 @@ class CreateNotificationsTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('notifications');
|
||||
$this->schema->drop('notifications');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreatePasswordTokensTable extends Migration
|
||||
|
@ -13,7 +13,7 @@ class CreatePasswordTokensTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('password_tokens', function (Blueprint $table) {
|
||||
$this->schema->create('password_tokens', function (Blueprint $table) {
|
||||
$table->string('id', 100)->primary();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->timestamp('created_at');
|
||||
|
@ -27,6 +27,6 @@ class CreatePasswordTokensTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('password_tokens');
|
||||
$this->schema->drop('password_tokens');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreatePermissionsTable extends Migration
|
||||
|
@ -14,7 +14,7 @@ class CreatePermissionsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('permissions', function ($table) {
|
||||
$this->schema->create('permissions', function (Blueprint $table) {
|
||||
|
||||
$table->integer('group_id')->unsigned();
|
||||
$table->string('permission', 100);
|
||||
|
@ -29,6 +29,6 @@ class CreatePermissionsTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('permissions');
|
||||
$this->schema->drop('permissions');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreatePostsTable extends Migration
|
||||
|
@ -14,7 +14,7 @@ class CreatePostsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('posts', function (Blueprint $table) {
|
||||
$this->schema->create('posts', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('discussion_id')->unsigned();
|
||||
$table->integer('number')->unsigned()->nullable();
|
||||
|
@ -34,7 +34,8 @@ class CreatePostsTable extends Migration
|
|||
$table->engine = 'MyISAM';
|
||||
});
|
||||
|
||||
app('db')->statement('ALTER TABLE posts ADD FULLTEXT content (content)');
|
||||
$prefix = $this->schema->getConnection()->getTablePrefix();
|
||||
$this->schema->getConnection()->statement('ALTER TABLE '.$prefix.'posts ADD FULLTEXT content (content)');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,6 +45,6 @@ class CreatePostsTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('posts');
|
||||
$this->schema->drop('posts');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateUsersDiscussionsTable extends Migration
|
||||
|
@ -14,7 +14,7 @@ class CreateUsersDiscussionsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users_discussions', function (Blueprint $table) {
|
||||
$this->schema->create('users_discussions', function (Blueprint $table) {
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->integer('discussion_id')->unsigned();
|
||||
$table->dateTime('read_time')->nullable();
|
||||
|
@ -30,6 +30,6 @@ class CreateUsersDiscussionsTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('users_discussions');
|
||||
$this->schema->drop('users_discussions');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateUsersGroupsTable extends Migration
|
||||
|
@ -14,7 +14,7 @@ class CreateUsersGroupsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users_groups', function (Blueprint $table) {
|
||||
$this->schema->create('users_groups', function (Blueprint $table) {
|
||||
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->integer('group_id')->unsigned();
|
||||
|
@ -29,6 +29,6 @@ class CreateUsersGroupsTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('users_groups');
|
||||
$this->schema->drop('users_groups');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Flarum\Install\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateUsersTable extends Migration
|
||||
|
@ -14,7 +14,7 @@ class CreateUsersTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$this->schema->create('users', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('username', 100)->unique();
|
||||
$table->string('email', 150)->unique();
|
||||
|
@ -39,6 +39,6 @@ class CreateUsersTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('users');
|
||||
$this->schema->drop('users');
|
||||
}
|
||||
}
|
||||
|
|
16
src/Install/Migration.php
Normal file
16
src/Install/Migration.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php namespace Flarum\Install;
|
||||
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
abstract class Migration
|
||||
{
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
protected $schema;
|
||||
|
||||
public function __construct(Builder $builder)
|
||||
{
|
||||
$this->schema = $builder;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user