mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
fix(backups): let service databases choose the databases to back up
Closes #12432 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
33a6682791
commit
dbd211486b
@@ -678,3 +678,39 @@ it('toggles the schedule from the form and notifies the page header', function (
|
||||
|
||||
expect((bool) $backup->fresh()->enabled)->toBeFalse();
|
||||
});
|
||||
|
||||
it('lets a service database backup choose the databases to back up', function (string $image, bool $showsSelection) {
|
||||
$server = Server::factory()->create(['team_id' => $this->team->id]);
|
||||
$destination = StandaloneDocker::where('server_id', $server->id)->firstOrFail();
|
||||
$project = Project::factory()->create(['team_id' => $this->team->id]);
|
||||
$environment = Environment::factory()->create(['project_id' => $project->id]);
|
||||
$service = Service::factory()->create([
|
||||
'server_id' => $server->id,
|
||||
'environment_id' => $environment->id,
|
||||
'destination_id' => $destination->id,
|
||||
'destination_type' => $destination->getMorphClass(),
|
||||
]);
|
||||
$database = ServiceDatabase::create(['service_id' => $service->id, 'name' => 'db', 'image' => $image]);
|
||||
$backup = ScheduledDatabaseBackup::create([
|
||||
'frequency' => '0 0 * * *',
|
||||
'database_type' => $database->getMorphClass(),
|
||||
'database_id' => $database->id,
|
||||
'team_id' => $this->team->id,
|
||||
]);
|
||||
|
||||
$component = Livewire::test(BackupEdit::class, ['backup' => $backup->fresh(), 'availableS3Storages' => collect()]);
|
||||
|
||||
$showsSelection
|
||||
? $component->assertSee('Database selection')->assertSee('Databases to back up')
|
||||
: $component->assertDontSee('Database selection');
|
||||
|
||||
if ($showsSelection) {
|
||||
$component->set('databasesToBackup', 'shop')->call('submit')->assertHasNoErrors();
|
||||
expect($backup->fresh()->databases_to_backup)->toBe('shop');
|
||||
}
|
||||
})->with([
|
||||
'mariadb' => ['mariadb:11', true],
|
||||
'mysql' => ['mysql:8', true],
|
||||
'postgres' => ['postgres:16-alpine', true],
|
||||
'mongodb' => ['mongo:7', false],
|
||||
]);
|
||||
|
||||
@@ -361,6 +361,35 @@ it('backs up a service database without a database env variable from the backup
|
||||
'mysql, selected database' => ['mysql:8', 'MYSQL_ROOT_PASSWORD=secret', ['databases_to_backup' => 'shop'], 'shop'],
|
||||
]);
|
||||
|
||||
it('backs up the databases from the backup settings instead of the container env database', function (string $image, string $env) {
|
||||
$database = backupRunSafetyServiceDatabase($this->server, $this->destination, $this->environment, $image);
|
||||
$backup = backupRunSafetySchedule($database, $this->team, ['databases_to_backup' => 'shop,blog']);
|
||||
backupRunSafetyFakeRemoteCommands(["docker exec '{$database->name}-{$database->service->uuid}' env" => $env]);
|
||||
|
||||
(new DatabaseBackupJob($backup))->handle();
|
||||
|
||||
expect(ScheduledDatabaseBackupExecution::query()->orderBy('id')->pluck('database_name')->all())->toBe(['shop', 'blog']);
|
||||
})->with([
|
||||
'mariadb' => ['mariadb:11', "MARIADB_ROOT_PASSWORD=secret\nMARIADB_DATABASE=app"],
|
||||
'mysql' => ['mysql:8', "MYSQL_ROOT_PASSWORD=secret\nMYSQL_DATABASE=app"],
|
||||
'postgres' => ['postgres:16', "POSTGRES_PASSWORD=secret\nPOSTGRES_DB=app"],
|
||||
]);
|
||||
|
||||
it('backs up the container env database when the backup settings name none', function (string $image, string $env) {
|
||||
$database = backupRunSafetyServiceDatabase($this->server, $this->destination, $this->environment, $image);
|
||||
$backup = backupRunSafetySchedule($database, $this->team);
|
||||
backupRunSafetyFakeRemoteCommands(["docker exec '{$database->name}-{$database->service->uuid}' env" => $env]);
|
||||
|
||||
(new DatabaseBackupJob($backup))->handle();
|
||||
|
||||
expect(ScheduledDatabaseBackupExecution::query()->sole()->database_name)->toBe('app');
|
||||
})->with([
|
||||
'mariadb' => ['mariadb:11', "MARIADB_ROOT_PASSWORD=secret\nMARIADB_DATABASE=app"],
|
||||
'mariadb with mysql env' => ['mariadb:11', "MARIADB_ROOT_PASSWORD=secret\nMYSQL_DATABASE=app"],
|
||||
'mysql' => ['mysql:8', "MYSQL_ROOT_PASSWORD=secret\nMYSQL_DATABASE=app"],
|
||||
'postgres' => ['postgres:16', "POSTGRES_PASSWORD=secret\nPOSTGRES_DB=app"],
|
||||
]);
|
||||
|
||||
it('records a failed execution and notifies when no service database to back up is known', function (string $image, string $env) {
|
||||
$database = backupRunSafetyServiceDatabase($this->server, $this->destination, $this->environment, $image);
|
||||
$backup = backupRunSafetySchedule($database, $this->team);
|
||||
|
||||
Reference in New Issue
Block a user