Allow Null = 0
Allow Value to be nullable, will autofill 0 if value is null or 0, to facilitate "unlimited" connections.
This commit is contained in:
parent
0ecfb40f5e
commit
82dd7dc8e3
8 changed files with 28 additions and 12 deletions
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
];
|
||||
|
|
|
@ -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',
|
||||
];
|
||||
|
|
|
@ -135,13 +135,17 @@ 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
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Give a specific user access to a given database.
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,9 @@ export default ({ database, className }: Props) => {
|
|||
addError({ key: 'database:delete', message: httpErrorToHuman(error) });
|
||||
});
|
||||
};
|
||||
if (!database.maxConnections){
|
||||
database.maxConnections = "Unlimited"
|
||||
}
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
|
|
|
@ -108,7 +108,11 @@
|
|||
<td class="middle">{{ $database->database }}</td>
|
||||
<td class="middle">{{ $database->username }}</td>
|
||||
<td class="middle">{{ $database->remote }}</td>
|
||||
@if($database->max_connections != null)
|
||||
<td class="middle">{{ $database->max_connections }}</td>
|
||||
@else
|
||||
<td class="middle">Unlimited</td>
|
||||
@endif
|
||||
<td class="text-center">
|
||||
<a href="{{ route('admin.servers.view.database', $database->getRelation('server')->id) }}">
|
||||
<button class="btn btn-xs btn-primary">Manage</button>
|
||||
|
|
|
@ -46,7 +46,11 @@
|
|||
<td>{{ $database->username }}</td>
|
||||
<td>{{ $database->remote }}</td>
|
||||
<td><code>{{ $database->host->host }}:{{ $database->host->port }}</code></td>
|
||||
@if($database->max_connections != null)
|
||||
<td>{{ $database->max_connections }}</td>
|
||||
@else
|
||||
<td>Unlimited</td>
|
||||
@endif
|
||||
<td class="text-center">
|
||||
<button data-action="reset-password" data-id="{{ $database->id }}" class="btn btn-xs btn-primary"><i class="fa fa-refresh"></i></button>
|
||||
<button data-action="remove" data-id="{{ $database->id }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
|
||||
|
@ -86,9 +90,9 @@
|
|||
<p class="text-muted small">This should reflect the IP address that connections are allowed from. Uses standard MySQL notation. If unsure leave as <code>%</code>.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pmax_connections" class="control-label">Max Concurrent Connections</label>
|
||||
<input id="pmax_connections" type="text" name="max_connections" class="form-control" value="150" />
|
||||
<p class="text-muted small">This should reflect the max number of concurrent connections from this user to the database. Use <code>0</code> for unlimited</p>
|
||||
<label for="pmax_connections" class="control-label">Concurrent Connections</label>
|
||||
<input id="pmax_connections" type="text" name="max_connections" class="form-control"/>
|
||||
<p class="text-muted small">This should reflect the max number of concurrent connections from this user to the database. Leave empty for unlimited.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
|
|
Loading…
Reference in a new issue