Skip to content

Commit 82dd7dc

Browse files
Allow Null = 0
Allow Value to be nullable, will autofill 0 if value is null or 0, to facilitate "unlimited" connections.
1 parent 0ecfb40 commit 82dd7dc

File tree

8 files changed

+28
-12
lines changed

8 files changed

+28
-12
lines changed

app/Contracts/Repository/DatabaseRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function createDatabase(string $database): bool;
6868
* @param string $username
6969
* @param string $remote
7070
* @param string $password
71-
* @param string $max_connections
71+
* @param $max_connections
7272
* @return bool
7373
*/
7474
public function createUser(string $username, string $remote, string $password, string $max_connections): bool;

app/Http/Requests/Admin/Servers/Databases/StoreServerDatabaseRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function rules(): array
2525
$query->where('database_host_id', $this->input('database_host_id') ?? 0);
2626
}),
2727
],
28+
'max_connections' => 'nullable',
2829
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
2930
'database_host_id' => 'required|integer|exists:database_hosts,id',
3031
];

app/Models/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Database extends Model
5151
'database_host_id' => 'required|exists:database_hosts,id',
5252
'database' => 'required|string|alpha_dash|between:3,100',
5353
'username' => 'string|alpha_dash|between:3,100',
54-
'max_connections' => 'string',
54+
'max_connections' => 'nullable',
5555
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
5656
'password' => 'string',
5757
];

app/Repositories/Eloquent/DatabaseRepository.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,16 @@ public function createDatabase(string $database): bool
135135
* @param string $username
136136
* @param string $remote
137137
* @param string $password
138-
* @param string $max_connections
138+
* @param $max_connections
139139
* @return bool
140140
*/
141-
public function createUser(string $username, string $remote, string $password, string $max_connections): bool
141+
public function createUser(string $username, string $remote, string $password, $max_connections): bool
142142
{
143-
return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\' WITH MAX_USER_CONNECTIONS %s', $username, $remote, $password, $max_connections));
143+
if (!$max_connections) {
144+
return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\'', $username, $remote, $password));
145+
} else {
146+
return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\' WITH MAX_USER_CONNECTIONS %s', $username, $remote, $password, $max_connections));
147+
}
144148
}
145149

146150
/**

database/migrations/2020_04_22_055500_add_max_connections_column.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AddMaxConnectionsColumnToDatabasesTable extends Migration
1414
public function up()
1515
{
1616
Schema::table('databases', function (Blueprint $table) {
17-
$table->integer('max_connections')->nullable(false)->default(0)->after('password');
17+
$table->integer('max_connections')->nullable()->default(0)->after('password');
1818
});
1919
}
2020

resources/scripts/components/server/databases/DatabaseRow.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export default ({ database, className }: Props) => {
5151
addError({ key: 'database:delete', message: httpErrorToHuman(error) });
5252
});
5353
};
54-
54+
if (!database.maxConnections){
55+
database.maxConnections = "Unlimited"
56+
}
57+
5558
return (
5659
<React.Fragment>
5760
<Formik

resources/views/admin/databases/view.blade.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@
108108
<td class="middle">{{ $database->database }}</td>
109109
<td class="middle">{{ $database->username }}</td>
110110
<td class="middle">{{ $database->remote }}</td>
111-
<td class="middle">{{ $database->max_connections }}</td>
111+
@if($database->max_connections != null)
112+
<td class="middle">{{ $database->max_connections }}</td>
113+
@else
114+
<td class="middle">Unlimited</td>
115+
@endif
112116
<td class="text-center">
113117
<a href="{{ route('admin.servers.view.database', $database->getRelation('server')->id) }}">
114118
<button class="btn btn-xs btn-primary">Manage</button>

resources/views/admin/servers/view/database.blade.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@
4646
<td>{{ $database->username }}</td>
4747
<td>{{ $database->remote }}</td>
4848
<td><code>{{ $database->host->host }}:{{ $database->host->port }}</code></td>
49-
<td>{{ $database->max_connections }}</td>
49+
@if($database->max_connections != null)
50+
<td>{{ $database->max_connections }}</td>
51+
@else
52+
<td>Unlimited</td>
53+
@endif
5054
<td class="text-center">
5155
<button data-action="reset-password" data-id="{{ $database->id }}" class="btn btn-xs btn-primary"><i class="fa fa-refresh"></i></button>
5256
<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 @@
8690
<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>
8791
</div>
8892
<div class="form-group">
89-
<label for="pmax_connections" class="control-label">Max Concurrent Connections</label>
90-
<input id="pmax_connections" type="text" name="max_connections" class="form-control" value="150" />
91-
<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>
93+
<label for="pmax_connections" class="control-label">Concurrent Connections</label>
94+
<input id="pmax_connections" type="text" name="max_connections" class="form-control"/>
95+
<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>
9296
</div>
9397
</div>
9498
<div class="box-footer">

0 commit comments

Comments
 (0)