diff --git a/app/Contracts/Repository/DatabaseRepositoryInterface.php b/app/Contracts/Repository/DatabaseRepositoryInterface.php index d0d982ef8..967ca20fb 100644 --- a/app/Contracts/Repository/DatabaseRepositoryInterface.php +++ b/app/Contracts/Repository/DatabaseRepositoryInterface.php @@ -68,7 +68,7 @@ interface DatabaseRepositoryInterface extends RepositoryInterface * @param string $username * @param string $remote * @param string $password - * @param string $max_connections + * @param $max_connections * @return bool */ public function createUser(string $username, string $remote, string $password, string $max_connections): bool; diff --git a/app/Http/Requests/Admin/Servers/Databases/StoreServerDatabaseRequest.php b/app/Http/Requests/Admin/Servers/Databases/StoreServerDatabaseRequest.php index ba8b76a83..40a4b06bc 100644 --- a/app/Http/Requests/Admin/Servers/Databases/StoreServerDatabaseRequest.php +++ b/app/Http/Requests/Admin/Servers/Databases/StoreServerDatabaseRequest.php @@ -25,6 +25,7 @@ class StoreServerDatabaseRequest extends AdminFormRequest $query->where('database_host_id', $this->input('database_host_id') ?? 0); }), ], + 'max_connections' => 'nullable', 'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/', 'database_host_id' => 'required|integer|exists:database_hosts,id', ]; diff --git a/app/Models/Database.php b/app/Models/Database.php index 6b8b16641..d2a7377f2 100644 --- a/app/Models/Database.php +++ b/app/Models/Database.php @@ -51,7 +51,7 @@ class Database extends Model 'database_host_id' => 'required|exists:database_hosts,id', 'database' => 'required|string|alpha_dash|between:3,100', 'username' => 'string|alpha_dash|between:3,100', - 'max_connections' => 'string', + 'max_connections' => 'nullable', 'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/', 'password' => 'string', ]; diff --git a/app/Repositories/Eloquent/DatabaseRepository.php b/app/Repositories/Eloquent/DatabaseRepository.php index eb19dd4b0..df9dbb6ee 100644 --- a/app/Repositories/Eloquent/DatabaseRepository.php +++ b/app/Repositories/Eloquent/DatabaseRepository.php @@ -135,12 +135,16 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor * @param string $username * @param string $remote * @param string $password - * @param string $max_connections + * @param $max_connections * @return bool */ - public function createUser(string $username, string $remote, string $password, string $max_connections): bool + public function createUser(string $username, string $remote, string $password, $max_connections): bool { - return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\' WITH MAX_USER_CONNECTIONS %s', $username, $remote, $password, $max_connections)); + if (!$max_connections) { + return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\'', $username, $remote, $password)); + } else { + return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\' WITH MAX_USER_CONNECTIONS %s', $username, $remote, $password, $max_connections)); + } } /** diff --git a/database/migrations/2020_04_22_055500_add_max_connections_column.php b/database/migrations/2020_04_22_055500_add_max_connections_column.php index e86622d37..9af4f4684 100644 --- a/database/migrations/2020_04_22_055500_add_max_connections_column.php +++ b/database/migrations/2020_04_22_055500_add_max_connections_column.php @@ -14,7 +14,7 @@ class AddMaxConnectionsColumnToDatabasesTable extends Migration public function up() { Schema::table('databases', function (Blueprint $table) { - $table->integer('max_connections')->nullable(false)->default(0)->after('password'); + $table->integer('max_connections')->nullable()->default(0)->after('password'); }); } diff --git a/resources/scripts/components/server/databases/DatabaseRow.tsx b/resources/scripts/components/server/databases/DatabaseRow.tsx index b1d549113..424f4498c 100644 --- a/resources/scripts/components/server/databases/DatabaseRow.tsx +++ b/resources/scripts/components/server/databases/DatabaseRow.tsx @@ -51,7 +51,10 @@ export default ({ database, className }: Props) => { addError({ key: 'database:delete', message: httpErrorToHuman(error) }); }); }; - + if (!database.maxConnections){ + database.maxConnections = "Unlimited" + } + return ( {{ $database->database }} {{ $database->username }} {{ $database->remote }} - {{ $database->max_connections }} + @if($database->max_connections != null) + {{ $database->max_connections }} + @else + Unlimited + @endif diff --git a/resources/views/admin/servers/view/database.blade.php b/resources/views/admin/servers/view/database.blade.php index 6b3133755..f861008eb 100644 --- a/resources/views/admin/servers/view/database.blade.php +++ b/resources/views/admin/servers/view/database.blade.php @@ -46,7 +46,11 @@ {{ $database->username }} {{ $database->remote }} {{ $database->host->host }}:{{ $database->host->port }} - {{ $database->max_connections }} + @if($database->max_connections != null) + {{ $database->max_connections }} + @else + Unlimited + @endif @@ -86,9 +90,9 @@

This should reflect the IP address that connections are allowed from. Uses standard MySQL notation. If unsure leave as %.

- - -

This should reflect the max number of concurrent connections from this user to the database. Use 0 for unlimited

+ + +

This should reflect the max number of concurrent connections from this user to the database. Leave empty for unlimited.