Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/Http/Requests/Admin/DatabaseHostFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ protected function getValidatorInstance(): Validator
$this->merge(['node_id' => null]);
}

if ($this->has('enabled')) {
$this->merge(['enabled' => $this->input('enabled') === '1' || $this->input('enabled') === true]);
} else {
$this->merge(['enabled' => false]);
}

return parent::getValidatorInstance();
}
}
5 changes: 4 additions & 1 deletion app/Models/DatabaseHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @property string $password
* @property int|null $max_databases
* @property int|null $node_id
* @property bool $enabled
* @property \Carbon\CarbonImmutable $created_at
* @property \Carbon\CarbonImmutable $updated_at
*/
Expand Down Expand Up @@ -45,7 +46,7 @@ class DatabaseHost extends Model
* Fields that are mass assignable.
*/
protected $fillable = [
'name', 'host', 'port', 'username', 'password', 'max_databases', 'node_id',
'name', 'host', 'port', 'username', 'password', 'max_databases', 'node_id', 'enabled',
];

/**
Expand All @@ -55,6 +56,7 @@ class DatabaseHost extends Model
'id' => 'integer',
'max_databases' => 'integer',
'node_id' => 'integer',
'enabled' => 'boolean',
];

/**
Expand All @@ -67,6 +69,7 @@ class DatabaseHost extends Model
'username' => 'required|string|max:32',
'password' => 'nullable|string',
'node_id' => 'sometimes|nullable|integer|exists:nodes,id',
'enabled' => 'sometimes|boolean',
];

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Databases/DeployServerDatabaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function handle(Server $server, array $data): Database
Assert::notEmpty($data['database'] ?? null);
Assert::notEmpty($data['remote'] ?? null);

$hosts = DatabaseHost::query()->get()->toBase();
$hosts = DatabaseHost::query()->where('enabled', true)->get()->toBase();
if ($hosts->isEmpty()) {
throw new NoSuitableDatabaseHostException();
} else {
Expand Down
1 change: 1 addition & 0 deletions app/Services/Databases/Hosts/HostCreationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function handle(array $data): DatabaseHost
'username' => array_get($data, 'username'),
'max_databases' => null,
'node_id' => array_get($data, 'node_id'),
'enabled' => array_get($data, 'enabled', true),
]);

// Confirm access using the provided credentials before saving data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function transform(DatabaseHost $model): array
'port' => $model->port,
'username' => $model->username,
'node' => $model->node_id,
'enabled' => $model->enabled,
'created_at' => $model->created_at->toAtomString(),
'updated_at' => $model->updated_at->toAtomString(),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function up(): void
$table->char('uuid', 36)->after('id');
$table->char('daemon_token_id', 16)->after('upload_size');

$table->renameColumn('`daemonSecret`', 'daemon_token');
$table->renameColumn('daemonSecret', 'daemon_token');
});

Schema::table('nodes', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('database_hosts', function (Blueprint $table) {
$table->boolean('enabled')->default(true)->after('node_id');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('database_hosts', function (Blueprint $table) {
$table->dropColumn('enabled');
});
}
};
15 changes: 15 additions & 0 deletions resources/views/admin/databases/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<th>Port</th>
<th>Username</th>
<th class="text-center">Databases</th>
<th class="text-center">Status</th>
<th class="text-center">Node</th>
</tr>
@foreach ($hosts as $host)
Expand All @@ -42,6 +43,13 @@
<td><code>{{ $host->port }}</code></td>
<td>{{ $host->username }}</td>
<td class="text-center">{{ $host->databases_count }}</td>
<td class="text-center">
@if($host->enabled)
<span class="label label-success">Enabled</span>
@else
<span class="label label-warning">Disabled</span>
@endif
</td>
<td class="text-center">
@if(! is_null($host->node))
<a href="{{ route('admin.nodes.view', $host->node->id) }}">{{ $host->node->name }}</a>
Expand Down Expand Up @@ -109,6 +117,13 @@
</select>
<p class="text-muted small">This setting does nothing other than default to this database host when adding a database to a server on the selected node.</p>
</div>
<div class="form-group">
<div class="checkbox checkbox-primary no-margin-bottom">
<input id="pEnabled" name="enabled" type="checkbox" value="1" checked />
<label for="pEnabled" class="strong">Enabled</label>
</div>
<p class="text-muted small no-margin-bottom">When disabled, this host will not be used for automatic database creation.</p>
</div>
</div>
<div class="modal-footer">
<p class="text-danger small text-left">The account defined for this database host <strong>must</strong> have the <code>WITH GRANT OPTION</code> permission. If the defined account does not have this permission requests to create databases <em>will</em> fail. <strong>Do not use the same account details for MySQL that you have defined for this panel.</strong></p>
Expand Down
16 changes: 16 additions & 0 deletions resources/views/admin/databases/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@

@section('content')
<form action="{{ route('admin.databases.view', $host->id) }}" method="POST">
@if($host->databases_count > 0 && !$host->enabled)
<div class="row">
<div class="col-xs-12">
<div class="alert alert-info">
<i class="fa fa-info-circle"></i> <strong>Note:</strong> This host currently has {{ $host->databases_count }} database(s). Disabling prevents new database creation, but existing databases continue to work.
</div>
</div>
</div>
@endif
<div class="row">
<div class="col-sm-6">
<div class="box box-primary">
Expand Down Expand Up @@ -50,6 +59,13 @@
</select>
<p class="text-muted small">This setting does nothing other than default to this database host when adding a database to a server on the selected node.</p>
</div>
<div class="form-group">
<div class="checkbox checkbox-primary no-margin-bottom">
<input id="pEnabled" name="enabled" type="checkbox" value="1" {{ $host->enabled ? 'checked' : '' }} />
<label for="pEnabled" class="strong">Enabled</label>
</div>
<p class="text-muted small">When disabled, this host will not be used for automatic database creation. Existing databases will continue to function normally.</p>
</div>
</div>
</div>
</div>
Expand Down