mirror of
https://github.com/flarum/framework.git
synced 2024-12-04 00:03:37 +08:00
split up the migration to create and seed notifications_from
This commit is contained in:
parent
66d32f2efb
commit
66ddbfb94d
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
];
|
Loading…
Reference in New Issue
Block a user