diff --git a/app/Http/Requests/Admin/DatabaseHostFormRequest.php b/app/Http/Requests/Admin/DatabaseHostFormRequest.php index 2e581478ec..a6e0cfed0a 100644 --- a/app/Http/Requests/Admin/DatabaseHostFormRequest.php +++ b/app/Http/Requests/Admin/DatabaseHostFormRequest.php @@ -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(); } } diff --git a/app/Models/DatabaseHost.php b/app/Models/DatabaseHost.php index f489998319..e32663efec 100644 --- a/app/Models/DatabaseHost.php +++ b/app/Models/DatabaseHost.php @@ -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 */ @@ -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', ]; /** @@ -55,6 +56,7 @@ class DatabaseHost extends Model 'id' => 'integer', 'max_databases' => 'integer', 'node_id' => 'integer', + 'enabled' => 'boolean', ]; /** @@ -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', ]; /** diff --git a/app/Services/Databases/DeployServerDatabaseService.php b/app/Services/Databases/DeployServerDatabaseService.php index e22eba51d4..71b9d402da 100644 --- a/app/Services/Databases/DeployServerDatabaseService.php +++ b/app/Services/Databases/DeployServerDatabaseService.php @@ -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 { diff --git a/app/Services/Databases/Hosts/HostCreationService.php b/app/Services/Databases/Hosts/HostCreationService.php index 0eecd7971f..7e24d7e87a 100644 --- a/app/Services/Databases/Hosts/HostCreationService.php +++ b/app/Services/Databases/Hosts/HostCreationService.php @@ -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. diff --git a/app/Transformers/Api/Application/DatabaseHostTransformer.php b/app/Transformers/Api/Application/DatabaseHostTransformer.php index 019fdf261d..2a87fe1db4 100644 --- a/app/Transformers/Api/Application/DatabaseHostTransformer.php +++ b/app/Transformers/Api/Application/DatabaseHostTransformer.php @@ -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(), ]; diff --git a/database/migrations/2020_04_10_141024_store_node_tokens_as_encrypted_value.php b/database/migrations/2020_04_10_141024_store_node_tokens_as_encrypted_value.php index 2e750dfa21..63498d3774 100644 --- a/database/migrations/2020_04_10_141024_store_node_tokens_as_encrypted_value.php +++ b/database/migrations/2020_04_10_141024_store_node_tokens_as_encrypted_value.php @@ -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) { diff --git a/database/migrations/2025_12_12_212512_add_enabled_column_to_database_hosts_table.php b/database/migrations/2025_12_12_212512_add_enabled_column_to_database_hosts_table.php new file mode 100644 index 0000000000..acaf7d7ba9 --- /dev/null +++ b/database/migrations/2025_12_12_212512_add_enabled_column_to_database_hosts_table.php @@ -0,0 +1,27 @@ +boolean('enabled')->default(true)->after('node_id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('database_hosts', function (Blueprint $table) { + $table->dropColumn('enabled'); + }); + } +}; diff --git a/resources/views/admin/databases/index.blade.php b/resources/views/admin/databases/index.blade.php index e4c69c5130..60e16b8868 100644 --- a/resources/views/admin/databases/index.blade.php +++ b/resources/views/admin/databases/index.blade.php @@ -32,6 +32,7 @@ Port Username Databases + Status Node @foreach ($hosts as $host) @@ -42,6 +43,13 @@ {{ $host->port }} {{ $host->username }} {{ $host->databases_count }} + + @if($host->enabled) + Enabled + @else + Disabled + @endif + @if(! is_null($host->node)) {{ $host->node->name }} @@ -109,6 +117,13 @@

This setting does nothing other than default to this database host when adding a database to a server on the selected node.

+
+
+ + +
+

When disabled, this host will not be used for automatic database creation.

+