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(); + } +];