Prevent an exception when creating databases with the same name on multiple hosts.
closes #1456
This commit is contained in:
parent
91c9cbba6f
commit
8253246955
4 changed files with 63 additions and 2 deletions
|
@ -7,6 +7,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
|
|||
### Fixed
|
||||
* Fixes a bug with the location update API endpoint throwing an error due to an unexected response value.
|
||||
* Fixes bug where node creation API endpoint was not correctly requiring the `disk_overallocate` key.
|
||||
* Prevents an exception from being thrown when a database with the same name is created on two different hosts.
|
||||
|
||||
### Changed
|
||||
* `allocation_limit` for servers now defaults to a null value, and is not required in PATCH/POST requests when adding
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Http\Requests\Admin\Servers\Databases;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
|
||||
|
||||
class StoreServerDatabaseRequest extends AdminFormRequest
|
||||
|
@ -14,7 +16,15 @@ class StoreServerDatabaseRequest extends AdminFormRequest
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'database' => 'required|string|min:1|max:24',
|
||||
'database' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:1',
|
||||
'max:24',
|
||||
Rule::unique('databases')->where(function (Builder $query) {
|
||||
$query->where('database_host_id', $this->input('database_host_id') ?? 0);
|
||||
}),
|
||||
],
|
||||
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
|
||||
'database_host_id' => 'required|integer|exists:database_hosts,id',
|
||||
];
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Http\Requests\Api\Application\Servers\Databases;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
|
@ -25,7 +27,15 @@ class StoreServerDatabaseRequest extends ApplicationApiRequest
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'database' => 'required|string|min:1|max:24',
|
||||
'database' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:1',
|
||||
'max:24',
|
||||
Rule::unique('databases')->where(function (Builder $query) {
|
||||
$query->where('database_host_id', $this->input('host') ?? 0);
|
||||
}),
|
||||
],
|
||||
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
|
||||
'host' => 'required|integer|exists:database_hosts,id',
|
||||
];
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class FixUniqueIndexToAccountForHost extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('databases', function (Blueprint $table) {
|
||||
$table->dropUnique(['database']);
|
||||
$table->dropUnique(['username']);
|
||||
|
||||
$table->unique(['database_host_id', 'database']);
|
||||
$table->unique(['database_host_id', 'username']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('databases', function (Blueprint $table) {
|
||||
$table->dropUnique(['database_host_id', 'database']);
|
||||
$table->dropUnique(['database_host_id', 'username']);
|
||||
|
||||
$table->unique(['database']);
|
||||
$table->unique(['username']);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue