From 1e372f3881aebb6aa930b53201067e593684607c Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Thu, 19 Jul 2018 09:22:34 +0200 Subject: [PATCH] split up the migration to create and seed notifications_from --- ...132900_create_notifications_from_table.php | 11 ------- ...8_132901_seed_notifications_from_table.php | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 migrations/2018_01_18_132901_seed_notifications_from_table.php diff --git a/migrations/2018_01_18_132900_create_notifications_from_table.php b/migrations/2018_01_18_132900_create_notifications_from_table.php index 83fad7b64..63fa38c8b 100644 --- a/migrations/2018_01_18_132900_create_notifications_from_table.php +++ b/migrations/2018_01_18_132900_create_notifications_from_table.php @@ -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) { diff --git a/migrations/2018_01_18_132901_seed_notifications_from_table.php b/migrations/2018_01_18_132901_seed_notifications_from_table.php new file mode 100644 index 000000000..c12fd4c22 --- /dev/null +++ b/migrations/2018_01_18_132901_seed_notifications_from_table.php @@ -0,0 +1,31 @@ + + * + * 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(); + } +];