diff --git a/app/Livewire/Admin/HostCreate.php b/app/Livewire/Admin/HostCreate.php index 9aeaf76..9048cc5 100644 --- a/app/Livewire/Admin/HostCreate.php +++ b/app/Livewire/Admin/HostCreate.php @@ -13,7 +13,7 @@ class HostCreate extends Component #[Validate('required|string|max:255')] public string $name = ''; - #[Validate('required|string|exists:datacenters,code')] + #[Validate('required|string|exists:datacenters,code,active,1')] public string $datacenter = ''; public function mount(): void diff --git a/database/migrations/2026_07_25_090004_make_customer_identity_unique.php b/database/migrations/2026_07_25_090004_make_customer_identity_unique.php new file mode 100644 index 0000000..8c0cc61 --- /dev/null +++ b/database/migrations/2026_07_25_090004_make_customer_identity_unique.php @@ -0,0 +1,27 @@ +unique('user_id'); // nullable — SQL permits multiple NULLs + }); + } + + public function down(): void + { + Schema::table('customers', function (Blueprint $table) { + $table->dropUnique(['user_id']); + }); + } +}; diff --git a/tests/Feature/Admin/DatacenterTest.php b/tests/Feature/Admin/DatacenterTest.php index 278b020..3916b12 100644 --- a/tests/Feature/Admin/DatacenterTest.php +++ b/tests/Feature/Admin/DatacenterTest.php @@ -59,3 +59,14 @@ it('offers only known datacenter codes when adding a host', function () { ->test(HostCreate::class) ->assertSet('datacenter', 'fsn'); }); + +it('rejects creating a host in an inactive datacenter', function () { + Datacenter::query()->firstOrCreate(['code' => 'fsn'], ['name' => 'Falkenstein']); + Datacenter::factory()->create(['code' => 'old', 'active' => false]); + + Livewire::actingAs(admin()) + ->test(HostCreate::class) + ->set('name', 'pve-old')->set('datacenter', 'old')->set('public_ip', '203.0.113.6')->set('root_password', 'supersecret') + ->call('save') + ->assertHasErrors(['datacenter']); +});