Use dependency injection in migrations

This commit is contained in:
Franz Liedke 2015-08-12 01:29:40 +02:00
parent 3679b38089
commit 2ce8b02245
14 changed files with 57 additions and 40 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateAccessTokensTable extends Migration class CreateAccessTokensTable extends Migration
@ -13,7 +13,7 @@ class CreateAccessTokensTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('access_tokens', function (Blueprint $table) { $this->schema->create('access_tokens', 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');
@ -28,6 +28,6 @@ class CreateAccessTokensTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('access_tokens'); $this->schema->drop('access_tokens');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateActivityTable extends Migration class CreateActivityTable extends Migration
@ -14,7 +14,7 @@ class CreateActivityTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('activity', function (Blueprint $table) { $this->schema->create('activity', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
$table->string('type', 100); $table->string('type', 100);
@ -31,6 +31,6 @@ class CreateActivityTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('activity'); $this->schema->drop('activity');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateConfigTable extends Migration class CreateConfigTable extends Migration
@ -14,7 +14,7 @@ class CreateConfigTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('config', function (Blueprint $table) { $this->schema->create('config', function (Blueprint $table) {
$table->string('key', 100)->primary(); $table->string('key', 100)->primary();
$table->binary('value')->nullable(); $table->binary('value')->nullable();
@ -28,6 +28,6 @@ class CreateConfigTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('config'); $this->schema->drop('config');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateDiscussionsTable extends Migration class CreateDiscussionsTable extends Migration
@ -14,7 +14,7 @@ class CreateDiscussionsTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('discussions', function (Blueprint $table) { $this->schema->create('discussions', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->string('title', 200); $table->string('title', 200);
@ -40,6 +40,6 @@ class CreateDiscussionsTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('discussions'); $this->schema->drop('discussions');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateEmailTokensTable extends Migration class CreateEmailTokensTable extends Migration
@ -13,7 +13,7 @@ class CreateEmailTokensTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('email_tokens', function (Blueprint $table) { $this->schema->create('email_tokens', function (Blueprint $table) {
$table->string('id', 100)->primary(); $table->string('id', 100)->primary();
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
$table->string('email', 150); $table->string('email', 150);
@ -28,6 +28,6 @@ class CreateEmailTokensTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('email_tokens'); $this->schema->drop('email_tokens');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateGroupsTable extends Migration class CreateGroupsTable extends Migration
@ -13,7 +13,7 @@ class CreateGroupsTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('groups', function (Blueprint $table) { $this->schema->create('groups', 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);
@ -29,6 +29,6 @@ class CreateGroupsTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('groups'); $this->schema->drop('groups');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateNotificationsTable extends Migration class CreateNotificationsTable extends Migration
@ -14,7 +14,7 @@ class CreateNotificationsTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('notifications', function (Blueprint $table) { $this->schema->create('notifications', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
@ -36,6 +36,6 @@ class CreateNotificationsTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('notifications'); $this->schema->drop('notifications');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreatePasswordTokensTable extends Migration class CreatePasswordTokensTable extends Migration
@ -13,7 +13,7 @@ class CreatePasswordTokensTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('password_tokens', function (Blueprint $table) { $this->schema->create('password_tokens', 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');
@ -27,6 +27,6 @@ class CreatePasswordTokensTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('password_tokens'); $this->schema->drop('password_tokens');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreatePermissionsTable extends Migration class CreatePermissionsTable extends Migration
@ -14,7 +14,7 @@ class CreatePermissionsTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('permissions', function ($table) { $this->schema->create('permissions', function (Blueprint $table) {
$table->integer('group_id')->unsigned(); $table->integer('group_id')->unsigned();
$table->string('permission', 100); $table->string('permission', 100);
@ -29,6 +29,6 @@ class CreatePermissionsTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('permissions'); $this->schema->drop('permissions');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreatePostsTable extends Migration class CreatePostsTable extends Migration
@ -14,7 +14,7 @@ class CreatePostsTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('posts', function (Blueprint $table) { $this->schema->create('posts', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->integer('discussion_id')->unsigned(); $table->integer('discussion_id')->unsigned();
$table->integer('number')->unsigned()->nullable(); $table->integer('number')->unsigned()->nullable();
@ -34,7 +34,8 @@ class CreatePostsTable extends Migration
$table->engine = 'MyISAM'; $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() public function down()
{ {
Schema::drop('posts'); $this->schema->drop('posts');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateUsersDiscussionsTable extends Migration class CreateUsersDiscussionsTable extends Migration
@ -14,7 +14,7 @@ class CreateUsersDiscussionsTable extends Migration
*/ */
public function up() 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('user_id')->unsigned();
$table->integer('discussion_id')->unsigned(); $table->integer('discussion_id')->unsigned();
$table->dateTime('read_time')->nullable(); $table->dateTime('read_time')->nullable();
@ -30,6 +30,6 @@ class CreateUsersDiscussionsTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('users_discussions'); $this->schema->drop('users_discussions');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateUsersGroupsTable extends Migration class CreateUsersGroupsTable extends Migration
@ -14,7 +14,7 @@ class CreateUsersGroupsTable extends Migration
*/ */
public function up() 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('user_id')->unsigned();
$table->integer('group_id')->unsigned(); $table->integer('group_id')->unsigned();
@ -29,6 +29,6 @@ class CreateUsersGroupsTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('users_groups'); $this->schema->drop('users_groups');
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
use Flarum\Install\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration class CreateUsersTable extends Migration
@ -14,7 +14,7 @@ class CreateUsersTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('users', function (Blueprint $table) { $this->schema->create('users', 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();
@ -39,6 +39,6 @@ class CreateUsersTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('users'); $this->schema->drop('users');
} }
} }

View 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;
}
}