Skip to content

Commit

Permalink
Fix index names in migrations
Browse files Browse the repository at this point in the history
This can be reverted when we upgrade to Laravel 5.7.
  • Loading branch information
tobyzerner committed Nov 27, 2018
1 parent 2b3f421 commit 988a317
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,15 +31,19 @@
})
->update(['user_id' => null]);

$schema->table('flags', function (Blueprint $table) {
$schema->table('flags', function (Blueprint $table) use ($schema) {
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

Migration::fixIndexNames($schema, $table);
});
},

'down' => function (Builder $schema) {
$schema->table('flags', function (Blueprint $table) {
$schema->table('flags', function (Blueprint $table) use ($schema) {
$table->dropForeign(['post_id', 'user_id']);

Migration::fixIndexNames($schema, $table);
});
}
];
9 changes: 7 additions & 2 deletions migrations/2018_09_15_043621_add_flags_indices.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@
* 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('flags', function (Blueprint $table) {
$schema->table('flags', function (Blueprint $table) use ($schema) {
$table->index('created_at');

Migration::fixIndexNames($schema, $table);
});
},

'down' => function (Builder $schema) {
$schema->table('flags', function (Blueprint $table) {
$schema->table('flags', function (Blueprint $table) use ($schema) {
$table->dropIndex(['created_at']);

Migration::fixIndexNames($schema, $table);
});
}
];

0 comments on commit 988a317

Please sign in to comment.