Add database and database users sync (#537)

* Add database and database users sync

* get mysl users

* add mariadb and postgres

* fix phpstan
This commit is contained in:
Saeed Vaziry
2025-03-12 22:59:25 +01:00
committed by GitHub
parent 493cbb0849
commit 0f06d81aac
17 changed files with 383 additions and 65 deletions

View File

@ -3,6 +3,7 @@
namespace App\Web\Pages\Servers\Databases;
use App\Actions\Database\CreateDatabase;
use App\Actions\Database\SyncDatabases;
use App\Models\Database;
use App\Models\Server;
use App\Web\Contracts\HasSecondSubNav;
@ -85,6 +86,26 @@ public static function getCollationInput(Server $server): Select
protected function getHeaderActions(): array
{
return [
Action::make('sync')
->color('gray')
->label('Sync Databases')
->icon('heroicon-o-arrow-path')
->authorize(fn () => auth()->user()?->can('create', [Database::class, $this->server]))
->requiresConfirmation()
->modalDescription('This will create databases that exist on the server but not in Vito.')
->modalSubmitActionLabel('Sync')
->action(function () {
run_action($this, function () {
app(SyncDatabases::class)->sync($this->server);
$this->dispatch('$refresh');
Notification::make()
->success()
->title('Databases synced!')
->send();
});
}),
Action::make('create')
->label('Create Database')
->icon('heroicon-o-plus')

View File

@ -4,6 +4,7 @@
use App\Actions\Database\CreateDatabase;
use App\Actions\Database\CreateDatabaseUser;
use App\Actions\Database\SyncDatabaseUsers;
use App\Models\DatabaseUser;
use App\Web\Contracts\HasSecondSubNav;
use App\Web\Pages\Servers\Page;
@ -29,6 +30,26 @@ public function mount(): void
protected function getHeaderActions(): array
{
return [
Action::make('sync')
->color('gray')
->label('Sync Users')
->icon('heroicon-o-arrow-path')
->authorize(fn () => auth()->user()?->can('create', [DatabaseUser::class, $this->server]))
->requiresConfirmation()
->modalDescription('This will create db users that exist on the server but not in Vito.')
->modalSubmitActionLabel('Sync')
->action(function () {
run_action($this, function () {
app(SyncDatabaseUsers::class)->sync($this->server);
$this->dispatch('$refresh');
Notification::make()
->success()
->title('Users synced!')
->send();
});
}),
Action::make('create')
->icon('heroicon-o-plus')
->modalWidth(MaxWidth::Large)
@ -43,6 +64,7 @@ protected function getHeaderActions(): array
Checkbox::make('remote')
->label('Remote')
->default(false)
->visible(in_array($this->server->database()->name, ['mysql', 'mariadb']))
->reactive(),
TextInput::make('host')
->label('Host')