Add forNetwork method to ServerFactory and update DatabaseSeeder to associate servers with a network

This commit is contained in:
2025-04-07 19:13:50 +01:00
parent 2b0f41cd7c
commit 2e2c0a033b
2 changed files with 19 additions and 2 deletions

View File

@@ -31,6 +31,15 @@ class ServerFactory extends Factory
]; ];
} }
public function forNetwork(string $networkId): static
{
return $this->state(function (array $attributes) use ($networkId) {
return [
'external_network_id' => $networkId,
];
});
}
public function forOrganisation(int $organisationId): static public function forOrganisation(int $organisationId): static
{ {
return $this->state(function (array $attributes) use ($organisationId) { return $this->state(function (array $attributes) use ($organisationId) {

View File

@@ -2,6 +2,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Enums\NetworkType;
use App\Enums\OrganisationRole; use App\Enums\OrganisationRole;
use App\Enums\ProviderType; use App\Enums\ProviderType;
use App\Enums\RepositoryType; use App\Enums\RepositoryType;
@@ -19,8 +20,6 @@ class DatabaseSeeder extends Seeder
*/ */
public function run(): void public function run(): void
{ {
// User::factory(10)->create();
$user = User::factory()->create([ $user = User::factory()->create([
'name' => 'Harry', 'name' => 'Harry',
'email' => 'harry@hjb.dev', 'email' => 'harry@hjb.dev',
@@ -39,7 +38,16 @@ class DatabaseSeeder extends Seeder
'token' => env('HETZNER_KEY'), 'token' => env('HETZNER_KEY'),
]); ]);
$network = $organisation->networks()->create([
'type' => NetworkType::EXTERNAL,
'name' => 'keystone',
'external_id' => 'net-12345',
'provider_id' => $provider->id,
'ip_range' => fake()->ipv4() . '/24',
]);
$servers = Server::factory(40) $servers = Server::factory(40)
->forNetwork($network->id)
->forOrganisation($organisation->id) ->forOrganisation($organisation->id)
->forProvider($provider->id) ->forProvider($provider->id)
->create(); ->create();