update logic call

This commit is contained in:
pbao9
2026-01-31 10:08:25 +07:00
parent 72b690f22e
commit 669ed87a05
144 changed files with 600 additions and 12093 deletions
@@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('module_folder', function (Blueprint $table) {
$table->unsignedBigInteger('module_datacenter_id')->nullable()->change();
});
// Clean up orphan records that point to non-existent datacenters
DB::table('module_folder')
->whereNotNull('module_datacenter_id')
->whereNotExists(function ($query) {
$query->select(DB::raw(1))
->from('module_datacenter')
->whereColumn('module_folder.module_datacenter_id', 'module_datacenter.id');
})
->update(['module_datacenter_id' => null]);
Schema::table('module_folder', function (Blueprint $table) {
$table->foreign('module_datacenter_id')
->references('id')
->on('module_datacenter')
->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('module_folder', function (Blueprint $table) {
$table->dropForeign(['module_datacenter_id']);
// Revert changes if necessary, though restoring invalid data isn't possible.
// We just restore the foreign key constraint if that was the intent.
$table->foreign('module_datacenter_id')->references('id')->on('module_datacenter')->onDelete('cascade');
});
}
};