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"); } } }