feat(domains): update unique constraint to composite with type and provider

- Remove single unique constraint on domain name
  - Add composite unique constraint on name, domain_type, and provider_type
  - Update Filament domain form validation with custom unique rule
  - Add descriptive validation message for duplicate domains
This commit is contained in:
idevakk
2025-12-08 10:57:56 -08:00
parent 8d8657cc5c
commit 1c4298cdaf
2 changed files with 52 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('domains', function (Blueprint $table) {
// Drop the existing unique constraint on 'name' column
$table->dropUnique('domains_name_unique');
// Add a composite unique constraint on name, domain_type, and provider_type
// This allows the same domain name with different type combinations
$table->unique(['name', 'domain_type', 'provider_type'], 'domains_name_type_provider_unique');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('domains', function (Blueprint $table) {
// Drop the composite unique constraint
$table->dropUnique('domains_name_type_provider_unique');
// Restore the original single unique constraint on 'name'
$table->unique('name', 'domains_name_unique');
});
}
};