From 3d2656bb021ffd1c3c78a08689d52211bad0622e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 27 Dec 2022 02:42:50 -0700 Subject: [PATCH] Add migration --- ...013417_add_can_trend_to_hashtags_table.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 database/migrations/2022_12_27_013417_add_can_trend_to_hashtags_table.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 new file mode 100644 index 000000000..f47e404f6 --- /dev/null +++ b/database/migrations/2022_12_27_013417_add_can_trend_to_hashtags_table.php @@ -0,0 +1,48 @@ +unsignedInteger('cached_count')->nullable(); + $table->boolean('can_trend')->nullable()->index()->after('slug'); + $table->boolean('can_search')->nullable()->index()->after('can_trend'); + $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(); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('hashtags', function (Blueprint $table) { + $table->dropColumn('cached_count'); + $table->dropColumn('can_trend'); + $table->dropColumn('can_search'); + $table->dropIndex('hashtags_is_nsfw_index'); + $table->dropIndex('hashtags_is_banned_index'); + }); + } +};