mirror of
https://github.com/flarum/core.git
synced 2025-07-16 06:16:23 +02:00
split up the migration to create and seed notifications_from
This commit is contained in:
@ -21,17 +21,6 @@ return [
|
|||||||
$table->foreign('id')->references('id')->on('notifications')->onDelete('cascade');
|
$table->foreign('id')->references('id')->on('notifications')->onDelete('cascade');
|
||||||
$table->foreign('from_user_id')->references('id')->on('users')->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) {
|
'down' => function (Builder $schema) {
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
];
|
Reference in New Issue
Block a user