From d6fbbb45aba7118fd1f434550bc2e4491fcd915d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 27 Dec 2022 03:37:27 -0700 Subject: [PATCH] Add migration --- ...013417_add_can_trend_to_hashtags_table.php | 8 ----- ...2022_12_27_102053_update_hashtag_count.php | 36 +++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 database/migrations/2022_12_27_102053_update_hashtag_count.php diff --git a/database/migrations/2022_12_27_013417_add_can_trend_to_hashtags_table.php b/database/migrations/2022_12_27_013417_add_can_trend_to_hashtags_table.php index f47e404f6..ca31c7b30 100644 --- a/database/migrations/2022_12_27_013417_add_can_trend_to_hashtags_table.php +++ b/database/migrations/2022_12_27_013417_add_can_trend_to_hashtags_table.php @@ -3,8 +3,6 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -use App\Hashtag; -use App\StatusHashtag; return new class extends Migration { @@ -22,12 +20,6 @@ return new class extends Migration $table->index('is_nsfw'); $table->index('is_banned'); }); - - foreach(Hashtag::cursor() as $hashtag) { - $count = StatusHashtag::whereHashtagId($hashtag->id)->count(); - $hashtag->cached_count = $count; - $hashtag->save(); - } } /** diff --git a/database/migrations/2022_12_27_102053_update_hashtag_count.php b/database/migrations/2022_12_27_102053_update_hashtag_count.php new file mode 100644 index 000000000..94d85e2cb --- /dev/null +++ b/database/migrations/2022_12_27_102053_update_hashtag_count.php @@ -0,0 +1,36 @@ +whereHashtagId($hashtag->id)->count(); + $hashtag->cached_count = $count; + $hashtag->save(); + } + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +};