Fix index names in migrations

This can be reverted when we upgrade to Laravel 5.7.
This commit is contained in:
Toby Zerner 2018-11-27 22:34:26 +10:30
parent 4483b7fee7
commit d08bb264b4
4 changed files with 29 additions and 9 deletions

View File

@ -9,21 +9,26 @@
* 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->table('tags', function (Blueprint $table) {
$schema->table('tags', function (Blueprint $table) use ($schema) {
$table->string('slug', 100)->change();
$table->unique('slug');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('tags', function (Blueprint $table) {
$schema->table('tags', function (Blueprint $table) use ($schema) {
$table->string('slug', 255)->change();
$table->dropUnique('tags_slug_unique');
$table->dropUnique(['slug']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,6 +9,7 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -30,16 +31,20 @@ return [
'last_posted_discussion_id' => $select('id', 'discussions', 'last_posted_discussion_id'),
]);
$schema->table('tags', function (Blueprint $table) {
$schema->table('tags', function (Blueprint $table) use ($schema) {
$table->foreign('parent_id')->references('id')->on('tags')->onDelete('set null');
$table->foreign('last_posted_user_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('last_posted_discussion_id')->references('id')->on('discussions')->onDelete('set null');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('tags', function (Blueprint $table) {
$schema->table('tags', function (Blueprint $table) use ($schema) {
$table->dropForeign(['parent_id', 'last_posted_discussion_id', 'last_posted_user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,6 +9,7 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -26,15 +27,19 @@ return [
})
->delete();
$schema->table('tag_user', function (Blueprint $table) {
$schema->table('tag_user', function (Blueprint $table) use ($schema) {
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('tag_user', function (Blueprint $table) {
$schema->table('tag_user', function (Blueprint $table) use ($schema) {
$table->dropForeign(['tag_id', 'user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,6 +9,7 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -26,15 +27,19 @@ return [
})
->delete();
$schema->table('discussion_tag', function (Blueprint $table) {
$schema->table('discussion_tag', function (Blueprint $table) use ($schema) {
$table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade');
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('discussion_tag', function (Blueprint $table) {
$schema->table('discussion_tag', function (Blueprint $table) use ($schema) {
$table->dropForeign(['discussion_id', 'tag_id']);
Migration::fixIndexNames($schema, $table);
});
}
];