Add mariadb missing blades (#476)

* Add missing views for Mariadb

* Add missing restore link

* adding test to avoid such issues

---------

Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
This commit is contained in:
Austin Kregel 2025-02-07 14:24:08 -05:00 committed by GitHub
parent 705d029a63
commit fd67097884
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 102 additions and 3 deletions

View File

@ -0,0 +1,11 @@
if ! sudo DEBIAN_FRONTEND=noninteractive mysqldump -u root {{ $database }} > {{ $file }}.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! DEBIAN_FRONTEND=noninteractive zip {{ $file }}.zip {{ $file }}.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! rm {{ $file }}.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,9 @@
if ! sudo mysql -e "CREATE USER IF NOT EXISTS '{{ $username }}'@'{{ $host }}' IDENTIFIED BY '{{ $password }}'"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"

View File

@ -0,0 +1,5 @@
if ! sudo mysql -e "CREATE DATABASE IF NOT EXISTS {{ $name }} CHARACTER SET utf8 COLLATE utf8_general_ci"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"

View File

@ -0,0 +1,9 @@
if ! sudo mysql -e "DROP USER IF EXISTS '{{ $username }}'@'{{ $host }}'"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"

View File

@ -0,0 +1,5 @@
if ! sudo mysql -e "DROP DATABASE IF EXISTS {{ $name }}"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"

View File

@ -0,0 +1,9 @@
if ! sudo mysql -e "GRANT ALL PRIVILEGES ON {{ $database }}.* TO '{{ $username }}'@'{{ $host }}'"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Linking to {{ $database }} finished"

View File

@ -0,0 +1,11 @@
if ! DEBIAN_FRONTEND=noninteractive unzip {{ $file }}.zip; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo DEBIAN_FRONTEND=noninteractive mysql -u root {{ $database }} < {{ $file }}.sql; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! rm {{ $file }}.sql {{ $file }}.zip; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -0,0 +1,5 @@
if ! sudo mysql -e "REVOKE ALL PRIVILEGES, GRANT OPTION FROM '{{ $username }}'@'{{ $host }}'"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"

View File

@ -22,11 +22,16 @@ class DatabaseBackupTest extends TestCase
{ {
use RefreshDatabase; use RefreshDatabase;
public function test_create_backup(): void /**
* @dataProvider data
*/
public function test_create_backup(string $db): void
{ {
SSH::fake(); SSH::fake();
Http::fake(); Http::fake();
$this->setupDatabase($db);
$this->actingAs($this->user); $this->actingAs($this->user);
$database = Database::factory()->create([ $database = Database::factory()->create([
@ -152,8 +157,13 @@ public function test_update_backup(): void
]); ]);
} }
public function test_delete_backup(): void /**
* @dataProvider data
*/
public function test_delete_backup(string $db): void
{ {
$this->setupDatabase($db);
$this->actingAs($this->user); $this->actingAs($this->user);
$database = Database::factory()->create([ $database = Database::factory()->create([
@ -182,11 +192,16 @@ public function test_delete_backup(): void
]); ]);
} }
public function test_restore_backup(): void /**
* @dataProvider data
*/
public function test_restore_backup(string $db): void
{ {
Http::fake(); Http::fake();
SSH::fake(); SSH::fake();
$this->setupDatabase($db);
$this->actingAs($this->user); $this->actingAs($this->user);
$database = Database::factory()->create([ $database = Database::factory()->create([
@ -220,4 +235,24 @@ public function test_restore_backup(): void
'status' => BackupFileStatus::RESTORED, 'status' => BackupFileStatus::RESTORED,
]); ]);
} }
private function setupDatabase(string $database): void
{
$this->server->services()->where('type', 'database')->delete();
$this->server->services()->create([
'type' => 'database',
'name' => config('core.databases_name.'.$database),
'version' => config('core.databases_version.'.$database),
]);
}
public static function data(): array
{
return [
[\App\Enums\Database::MYSQL80],
[\App\Enums\Database::MARIADB104],
[\App\Enums\Database::POSTGRESQL16],
];
}
} }