Refactor VM provisioning pipeline into focused services and add IP pool
management
This commit is contained in:
@@ -12,10 +12,23 @@ return new class extends Migration {
|
||||
{
|
||||
Schema::create('ip_pools', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->uuid('uuid')->unique();
|
||||
|
||||
$table->string('ip_address');
|
||||
|
||||
$table->unsignedBigInteger('module_network_id');
|
||||
$table->foreign('module_network_id')->references('id')->on('module_network');
|
||||
|
||||
$table->enum('status', ['free', 'assigned', 'reserved'])->default('free');
|
||||
|
||||
$table->unsignedBigInteger('service_id')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['module_network_id', 'status']);
|
||||
$table->index('service_id');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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
|
||||
{
|
||||
if (!Schema::hasColumn('products', 'thumbnail')) {
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->string('thumbnail')->nullable()->after('description');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// The base create_products migration already defines this nullable column.
|
||||
// Keep rollback as a no-op so rolling back this compatibility migration
|
||||
// cannot remove an existing column from fresh databases.
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('ip_pools', function (Blueprint $table) {
|
||||
$table->uuid('uuid')->nullable()->unique()->after('id');
|
||||
});
|
||||
|
||||
// Backfill existing rows
|
||||
DB::table('ip_pools')->whereNull('uuid')->orderBy('id')->each(function ($row) {
|
||||
DB::table('ip_pools')->where('id', $row->id)->update(['uuid' => (string) Str::uuid()]);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('ip_pools', function (Blueprint $table) {
|
||||
$table->dropColumn('uuid');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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('virtual_machines', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('ip_pool_id')->nullable()->after('host_id');
|
||||
$table->string('ip', 45)->nullable()->after('ip_pool_id');
|
||||
|
||||
$table->foreign('ip_pool_id')
|
||||
->references('id')
|
||||
->on('ip_pools')
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('virtual_machines', function (Blueprint $table) {
|
||||
$table->dropForeign(['ip_pool_id']);
|
||||
$table->dropColumn(['ip_pool_id', 'ip']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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('ip_pools', function (Blueprint $table) {
|
||||
$table->string('gateway')->nullable()->after('ip_address');
|
||||
$table->unsignedTinyInteger('cidr')->default(24)->after('gateway');
|
||||
|
||||
$table
|
||||
->enum('status', ['free', 'assigned', 'reserved'])
|
||||
->default('free')
|
||||
->after('module_network_id');
|
||||
|
||||
$table->foreignId('service_id')->nullable()->after('status')->constrained('services')->nullOnDelete();
|
||||
|
||||
$table->index(['status', 'module_network_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('ip_pools', function (Blueprint $table) {
|
||||
$table->dropForeign(['service_id']);
|
||||
$table->dropIndex(['status', 'module_network_id']);
|
||||
|
||||
$table->dropColumn(['gateway', 'cidr', 'status', 'service_id']);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user