fix: slug unique check skips soft-deleted + drop DB unique on companies.slug
DB-level unique blocks INSERT even when previous record is soft-deleted. MariaDB doesn't support partial unique indexes, so we drop the constraint and rely on Filament validation + provisioner check (whereNull deleted_at).
This commit is contained in:
@@ -35,7 +35,10 @@ class CompanyResource extends Resource
|
|||||||
->required()
|
->required()
|
||||||
->alphaDash()
|
->alphaDash()
|
||||||
->maxLength(30)
|
->maxLength(30)
|
||||||
->unique(ignoreRecord: true)
|
->unique(
|
||||||
|
ignoreRecord: true,
|
||||||
|
modifyRuleUsing: fn ($rule) => $rule->whereNull('deleted_at'),
|
||||||
|
)
|
||||||
->dehydrateStateUsing(fn ($state) => strtolower((string) $state))
|
->dehydrateStateUsing(fn ($state) => strtolower((string) $state))
|
||||||
->extraInputAttributes(['style' => 'text-transform: lowercase'])
|
->extraInputAttributes(['style' => 'text-transform: lowercase'])
|
||||||
->helperText('Subdomeniul: <slug>.service.mir.md'),
|
->helperText('Subdomeniul: <slug>.service.mir.md'),
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* MariaDB nu suportă partial unique indexes (UNIQUE WHERE deleted_at IS NULL).
|
||||||
|
* Drop unique-ul fizic și păstrăm doar index pentru performanță;
|
||||||
|
* unicitatea slug-ului e impusă la nivel de validare Filament + provisioner.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('companies', function (Blueprint $t) {
|
||||||
|
// Drop existing unique (default name companies_slug_unique).
|
||||||
|
try { $t->dropUnique('companies_slug_unique'); } catch (\Throwable $e) {}
|
||||||
|
$t->index('slug', 'companies_slug_index');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('companies', function (Blueprint $t) {
|
||||||
|
try { $t->dropIndex('companies_slug_index'); } catch (\Throwable $e) {}
|
||||||
|
$t->unique('slug', 'companies_slug_unique');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user