fix: 🐛 update unique key based on id_key and delete_at date in dynamic pages

This commit is contained in:
Alexis Gousseau 2026-01-12 10:31:33 +01:00
parent 49884d510a
commit 6a84e94f55
2 changed files with 42 additions and 1 deletions

View file

@ -123,7 +123,6 @@ class DynamicPageController extends Controller
{
return DB::transaction(function () use ($request) {
$dynamicPageModel = new DynamicPage();
$dynamicPageModel->inertiaFill($request->validated());
if ($dynamicPageModel->saveOrFail()) {

View file

@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
// Delete old key.
Schema::table('dynamic_pages', function (Blueprint $table) {
$table->dropUnique('dynamic_pages_id_key_unique');
});
// Set new unique key with delete_at date.
Schema::table('dynamic_pages', function (Blueprint $table) {
$table->unique(['id_key', 'deleted_at'], 'dynamic_pages_id_key_deleted_at_unique');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
// Delete old key.
Schema::table('dynamic_pages', function (Blueprint $table) {
$table->dropUnique('dynamic_pages_id_key_deleted_at_unique');
});
// Set new unique key.
Schema::table('dynamic_pages', function (Blueprint $table) {
$table->unique('id_key', 'dynamic_pages_id_key_unique');
});
}
};