update network moudle

This commit is contained in:
pbao9
2026-01-31 10:25:21 +07:00
parent 745e7f71ec
commit 4b5e22c9d2
11 changed files with 277 additions and 179 deletions
@@ -18,7 +18,7 @@ return new class extends Migration
$table->string('name',255)->nullable();
$table->string('type',100)->nullable();
$table->string('network',100)->nullable();
$table->bigInteger('module_host_id')->default(0)->index();
$table->foreignId('module_host_id')->constrained('module_host')->index()->cascadeOnDelete();
$table->timestamps();
});
}
@@ -30,6 +30,6 @@ return new class extends Migration
*/
public function down()
{
Schema::dropIfExists('module_networks');
Schema::dropIfExists('module_network');
}
};
@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('module_network', function (Blueprint $table) {
$table->unsignedBigInteger('module_host_id')->nullable()->change();
});
// Clean up orphan records that point to non-existent datacenters
DB::table('module_network')
->whereNotNull('module_host_id')
->whereNotExists(function ($query) {
$query->select(DB::raw(1))
->from('module_host')
->whereColumn('module_network.module_host_id', 'module_host.id');
})
->update(['module_host_id' => null]);
Schema::table('module_network', function (Blueprint $table) {
$table->foreign('module_host_id')
->references('id')
->on('module_host')
->cascadeOnDelete();
});
}
public function down(): void
{
Schema::table('module_network', function (Blueprint $table) {
$table->unsignedBigInteger('module_host_id')->change();
});
}
};