Prevent duplicate allocations for servers
This commit is contained in:
parent
241f7d0125
commit
d86c35d80f
3 changed files with 35 additions and 2 deletions
|
@ -17,6 +17,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
|
|||
### Added
|
||||
* Added ability to search the following API endpoints: list users, list servers, and list locations.
|
||||
* 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.
|
||||
* 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.
|
||||
|
||||
### Changed
|
||||
* PHP 7.2 is now the minimum required version for this software.
|
||||
|
|
|
@ -83,7 +83,7 @@ class Server extends Model implements CleansAttributes, ValidableContract
|
|||
'io' => 'numeric|between:10,1000',
|
||||
'cpu' => 'numeric|min:0',
|
||||
'disk' => 'numeric|min:0',
|
||||
'allocation_id' => 'exists:allocations,id',
|
||||
'allocation_id' => 'bail|unique:servers|exists:allocations,id',
|
||||
'nest_id' => 'exists:nests,id',
|
||||
'egg_id' => 'exists:eggs,id',
|
||||
'pack_id' => 'nullable|numeric|min:0',
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class EnsureUniqueAllocationIdOnServersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->unique(['allocation_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->dropUnique(['allocation_id']);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue