From 381c626a5bdc16762fb9bcb4ea83ecddb48313b0 Mon Sep 17 00:00:00 2001 From: ketan-canyon Date: Wed, 30 Oct 2024 18:53:08 +0000 Subject: [PATCH] Worked on PR review changes --- ...ble_in_knowledge_base_categories_table.php | 21 +++++++++++++++++++ ...ug_in_knowledge_base_categories_table.php} | 16 +++++--------- 2 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 app-modules/knowledge-base/database/migrations/2024_10_30_184250_update_slug_column_to_not_nullable_in_knowledge_base_categories_table.php rename app-modules/knowledge-base/database/migrations/{2024_10_29_183334_data_add_remainig_slug_in_knowledge_base_categories_table.php => 2024_10_30_184951_data_add_remainig_slug_in_knowledge_base_categories_table.php} (64%) diff --git a/app-modules/knowledge-base/database/migrations/2024_10_30_184250_update_slug_column_to_not_nullable_in_knowledge_base_categories_table.php b/app-modules/knowledge-base/database/migrations/2024_10_30_184250_update_slug_column_to_not_nullable_in_knowledge_base_categories_table.php new file mode 100644 index 000000000..adf265080 --- /dev/null +++ b/app-modules/knowledge-base/database/migrations/2024_10_30_184250_update_slug_column_to_not_nullable_in_knowledge_base_categories_table.php @@ -0,0 +1,21 @@ +string('slug')->nullable(false)->change(); + }); + } + + public function down(): void + { + Schema::table('knowledge_base_categories', function (Blueprint $table) { + $table->string('slug')->nullable()->change(); + }); + } +}; diff --git a/app-modules/knowledge-base/database/migrations/2024_10_29_183334_data_add_remainig_slug_in_knowledge_base_categories_table.php b/app-modules/knowledge-base/database/migrations/2024_10_30_184951_data_add_remainig_slug_in_knowledge_base_categories_table.php similarity index 64% rename from app-modules/knowledge-base/database/migrations/2024_10_29_183334_data_add_remainig_slug_in_knowledge_base_categories_table.php rename to app-modules/knowledge-base/database/migrations/2024_10_30_184951_data_add_remainig_slug_in_knowledge_base_categories_table.php index d3be0282c..49415dc7c 100644 --- a/app-modules/knowledge-base/database/migrations/2024_10_29_183334_data_add_remainig_slug_in_knowledge_base_categories_table.php +++ b/app-modules/knowledge-base/database/migrations/2024_10_30_184951_data_add_remainig_slug_in_knowledge_base_categories_table.php @@ -2,10 +2,9 @@ use Illuminate\Support\Str; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Log; -use Illuminate\Database\QueryException; use Illuminate\Database\Migrations\Migration; use AidingApp\KnowledgeBase\Models\KnowledgeBaseCategory; +use Illuminate\Database\UniqueConstraintViolationException; return new class () extends Migration { public function up(): void @@ -27,20 +26,15 @@ public function up(): void DB::commit(); break; - } catch (QueryException $e) { + } catch (UniqueConstraintViolationException $e) { DB::rollBack(); - - if ($e->errorInfo[1] === 7) { - $attempts++; - $slug = $baseSlug . '-' . $attempts; - } else { - throw $e; - } + $attempts++; + $slug = $baseSlug . '-' . $attempts; } } if ($attempts == 15) { - Log::info("Failed to generate a unique slug after 15 attempts for category ID {$category->name}\n"); + throw new Exception("Failed to generate a unique slug after 15 attempts for category ID {$category->name}\n"); } } }