moving to provider stored in database

This commit is contained in:
2025-04-07 14:38:28 +01:00
parent 6bd12bd6ca
commit b800a9d83a
11 changed files with 100 additions and 14 deletions

View File

@@ -20,8 +20,6 @@ class ServerFactory extends Factory
{
return [
'name' => $this->faker->word(),
'provider' => ServerProvider::HETZNER,
'provider_id' => $this->faker->uuid(),
'ipv4' => $this->faker->ipv4(),
'ipv6' => $this->faker->ipv6(),
'provider_status' => '',
@@ -41,4 +39,13 @@ class ServerFactory extends Factory
];
});
}
public function forProvider(string $providerId): static
{
return $this->state(function (array $attributes) use ($providerId) {
return [
'provider_id' => $providerId,
];
});
}
}

View File

@@ -2,6 +2,7 @@
use App\Models\Network;
use App\Models\Organisation;
use App\Models\Provider;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -15,9 +16,9 @@ return new class extends Migration
$table->foreignIdFor(Organisation::class);
$table->foreignIdFor(Network::class, 'external_network_id');
$table->foreignIdFor(Network::class, 'internal_network_id');
$table->foreignIdFor(Provider::class);
$table->string('provider_external_id')->nullable();
$table->string('name');
$table->string('provider');
$table->string('provider_id');
$table->string('ipv4');
$table->string('ipv6');
$table->string('private_ip');

View File

@@ -1,6 +1,7 @@
<?php
use App\Models\Organisation;
use App\Models\Provider;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -12,9 +13,9 @@ return new class extends Migration
Schema::create('networks', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Organisation::class);
$table->foreignIdFor(Provider::class);
$table->string('provider_external_id')->nullable();
$table->string('type');
$table->string('provider')->nullable();
$table->string('provider_id')->nullable();
$table->string('name');
$table->string('ip_range');
$table->timestamps();

View File

@@ -0,0 +1,29 @@
<?php
use App\Models\Organisation;
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::create('providers', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Organisation::class);
$table->string('name');
$table->string('type');
$table->text('token');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('providers');
}
};

View File

@@ -3,6 +3,7 @@
namespace Database\Seeders;
use App\Enums\OrganisationRole;
use App\Enums\ProviderType;
use App\Enums\RepositoryType;
use App\Models\Organisation;
use App\Models\Server;
@@ -32,7 +33,16 @@ class DatabaseSeeder extends Seeder
'owner_id' => 1,
]);
$servers = Server::factory(40)->forOrganisation($organisation->id)->create();
$provider = $organisation->providers()->create([
'name' => 'Hetzner',
'type' => ProviderType::HETZNER,
'token' => env('HETZNER_KEY'),
]);
$servers = Server::factory(40)
->forOrganisation($organisation->id)
->forProvider($provider->id)
->create();
$organisation->servers()->saveMany($servers);