From 64059cb47e74011476b091dad0ffc4294ee2eab0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 May 2023 23:34:06 -0600 Subject: [PATCH] Add postgres migration to fix duplicate hashtags --- ...023_05_03_042219_fix_postgres_hashtags.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 database/migrations/2023_05_03_042219_fix_postgres_hashtags.php diff --git a/database/migrations/2023_05_03_042219_fix_postgres_hashtags.php b/database/migrations/2023_05_03_042219_fix_postgres_hashtags.php new file mode 100644 index 000000000..1d4b1e820 --- /dev/null +++ b/database/migrations/2023_05_03_042219_fix_postgres_hashtags.php @@ -0,0 +1,46 @@ +name)->orderBy('id')->get(); + if($dups->count() === 1) { + continue; + } + + $first = $dups->shift(); + $dups->each(function($dup) use($first) { + StatusHashtag::whereHashtagId($dup->id)->update(['hashtag_id' => $first->id]); + $dup->delete(); + }); + } + + Cache::clear(); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +};