Use new migration format

This commit is contained in:
Franz Liedke 2016-02-24 23:14:20 +09:00
parent fb67393f81
commit dd92088b5c
5 changed files with 46 additions and 71 deletions

View File

@ -8,24 +8,19 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tags\Migration;
use Flarum\Database\AbstractMigration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
class CreateDiscussionsTagsTable extends AbstractMigration return [
{ 'up' => function (Builder $schema) {
public function up() $schema->create('discussions_tags', function (Blueprint $table) {
{
$this->schema->create('discussions_tags', function (Blueprint $table) {
$table->integer('discussion_id')->unsigned(); $table->integer('discussion_id')->unsigned();
$table->integer('tag_id')->unsigned(); $table->integer('tag_id')->unsigned();
$table->primary(['discussion_id', 'tag_id']); $table->primary(['discussion_id', 'tag_id']);
}); });
} },
public function down() 'down' => function (Builder $schema) {
{ $schema->drop('discussions_tags');
$this->schema->drop('discussions_tags');
} }
} ];

View File

@ -8,17 +8,13 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tags\Migration;
use Flarum\Database\AbstractMigration;
use Flarum\Tags\Tag; use Flarum\Tags\Tag;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
class CreateTagsTable extends AbstractMigration return [
{ 'up' => function (Builder $schema) {
public function up() $schema->create('tags', function (Blueprint $table) {
{
$this->schema->create('tags', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->string('name', 100); $table->string('name', 100);
$table->string('slug', 100); $table->string('slug', 100);
@ -46,10 +42,9 @@ class CreateTagsTable extends AbstractMigration
'color' => '#888', 'color' => '#888',
'position' => '0' 'position' => '0'
]); ]);
} },
public function down() 'down' => function (Builder $schema) {
{ $schema->drop('tags');
$this->schema->drop('tags');
} }
} ];

View File

@ -8,26 +8,21 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tags\Migration;
use Flarum\Database\AbstractMigration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
class CreateUsersTagsTable extends AbstractMigration return [
{ 'up' => function (Builder $schema) {
public function up() $schema->create('users_tags', function (Blueprint $table) {
{
$this->schema->create('users_tags', function (Blueprint $table) {
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
$table->integer('tag_id')->unsigned(); $table->integer('tag_id')->unsigned();
$table->dateTime('read_time')->nullable(); $table->dateTime('read_time')->nullable();
$table->boolean('is_hidden')->default(0); $table->boolean('is_hidden')->default(0);
$table->primary(['user_id', 'tag_id']); $table->primary(['user_id', 'tag_id']);
}); });
} },
public function down() 'down' => function (Builder $schema) {
{ $schema->drop('users_tags');
$this->schema->drop('users_tags');
} }
} ];

View File

@ -8,25 +8,20 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tags\Migration; use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Database\AbstractMigration; return [
'up' => function (SettingsRepositoryInterface $settings) {
$settings->set('flarum-tags.max_primary_tags', '1');
$settings->set('flarum-tags.min_primary_tags', '1');
$settings->set('flarum-tags.max_secondary_tags', '3');
$settings->set('flarum-tags.min_secondary_tags', '0');
},
class SetDefaultSettings extends AbstractMigration 'down' => function (SettingsRepositoryInterface $settings) {
{ $settings->delete('flarum-tags.max_primary_tags');
public function up() $settings->delete('flarum-tags.max_secondary_tags');
{ $settings->delete('flarum-tags.min_primary_tags');
$this->settings->set('flarum-tags.max_primary_tags', '1'); $settings->delete('flarum-tags.min_secondary_tags');
$this->settings->set('flarum-tags.min_primary_tags', '1');
$this->settings->set('flarum-tags.max_secondary_tags', '3');
$this->settings->set('flarum-tags.min_secondary_tags', '0');
} }
];
public function down()
{
$this->settings->delete('flarum-tags.max_primary_tags');
$this->settings->delete('flarum-tags.max_secondary_tags');
$this->settings->delete('flarum-tags.min_primary_tags');
$this->settings->delete('flarum-tags.min_secondary_tags');
}
}

View File

@ -1,25 +1,20 @@
<?php <?php
namespace Flarum\Tags\Migration;
use Flarum\Database\AbstractMigration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
class MakeSlugUnique extends AbstractMigration return [
{ 'up' => function (Builder $schema) {
public function up() $schema->table('tags', function (Blueprint $table) {
{
$this->schema->table('tags', function (Blueprint $table) {
$table->string('slug', 100)->change(); $table->string('slug', 100)->change();
$table->unique('slug'); $table->unique('slug');
}); });
} },
public function down() 'down' => function (Builder $schema) {
{ $schema->table('tags', function (Blueprint $table) {
$this->schema->table('tags', function (Blueprint $table) {
$table->string('slug', 255)->change(); $table->string('slug', 255)->change();
$table->dropUnique('tags_slug_unique'); $table->dropUnique('tags_slug_unique');
}); });
} }
} ];