split up the migration to create and seed notifications_from

This commit is contained in:
Daniel Klabbers 2018-07-19 09:22:34 +02:00
parent 66d32f2efb
commit 66ddbfb94d
2 changed files with 31 additions and 11 deletions

View File

@ -21,17 +21,6 @@ return [
$table->foreign('id')->references('id')->on('notifications')->onDelete('cascade');
$table->foreign('from_user_id')->references('id')->on('users')->onDelete('cascade');
});
$schema->getConnection()->table('notifications')->chunkById(100, function ($notifications) use ($schema) {
foreach ($notifications as $notification) {
$insert = [
'id' => $notification->id,
'from_user_id' => $notification->sender_id
];
$schema->getConnection()->table('notifications_from')->updateOrInsert($insert, $insert);
}
});
},
'down' => function (Builder $schema) {

View File

@ -0,0 +1,31 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->getConnection()->table('notifications')->chunkById(100, function ($notifications) use ($schema) {
foreach ($notifications as $notification) {
$insert = [
'id' => $notification->id,
'from_user_id' => $notification->sender_id
];
$schema->getConnection()->table('notifications_from')->updateOrInsert($insert, $insert);
}
});
},
'down' => function (Builder $schema) {
$schema->getConnection()->table('notifications_from')->truncate();
}
];