Skip to content

Commit d86c35d

Browse files
committed
Prevent duplicate allocations for servers
1 parent 241f7d0 commit d86c35d

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1717
### Added
1818
* Added ability to search the following API endpoints: list users, list servers, and list locations.
1919
* Add support for finding a user by external ID using `/api/application/users/external/<id>` or by passing it as the search term when listing all users.
20-
20+
* Added a unique key to the servers table to data integrity issues where an allocation would be assigned to more than one server at once.
21+
2122
### Changed
2223
* PHP 7.2 is now the minimum required version for this software.
2324
* Egg variable default values are no longer validated aganist the ruleset when configuring them. Validation of those rules will only occur when editing or creating a server.

app/Models/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Server extends Model implements CleansAttributes, ValidableContract
8383
'io' => 'numeric|between:10,1000',
8484
'cpu' => 'numeric|min:0',
8585
'disk' => 'numeric|min:0',
86-
'allocation_id' => 'exists:allocations,id',
86+
'allocation_id' => 'bail|unique:servers|exists:allocations,id',
8787
'nest_id' => 'exists:nests,id',
8888
'egg_id' => 'exists:eggs,id',
8989
'pack_id' => 'nullable|numeric|min:0',
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class EnsureUniqueAllocationIdOnServersTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('servers', function (Blueprint $table) {
17+
$table->unique(['allocation_id']);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('servers', function (Blueprint $table) {
29+
$table->dropUnique(['allocation_id']);
30+
});
31+
}
32+
}

0 commit comments

Comments
 (0)