fix(backups): preserve backup state when cloning databases

This commit is contained in:
Andras Bacsai
2026-08-20 20:23:54 +02:00
parent 3b69514085
commit 14f86cd094
4 changed files with 19 additions and 2 deletions
@@ -4887,6 +4887,8 @@ class DatabasesController extends Controller
'id',
'created_at',
'updated_at',
'last_execution_at',
'missing_backup_notification_sent_at',
])->fill([
'uuid' => new_public_id(),
'database_id' => $newDatabase->id,
@@ -92,7 +92,7 @@
<x-forms.input label="Timeout" id="timeout" type="number" min="60"
helper="Maximum backup runtime in seconds." required />
<x-forms.input label="Missing backup alert after" id="missingBackupNotificationDays" type="number"
min="0" max="365" suffix="days"
min="0" max="365" suffix="days" canGate="manageBackups" :canResource="$backup->database"
helper="Notify through backup failure channels after this many days without an execution. Use 0 to disable." required />
</div>
</div>
+14 -1
View File
@@ -137,6 +137,16 @@ describe('POST /api/v1/databases/{uuid}/clone', function () {
'destination_id' => $this->destination->id,
'destination_type' => $this->destination->getMorphClass(),
]);
$backup = $database->scheduledBackups()->create([
'team_id' => $this->team->id,
'enabled' => true,
'frequency' => '0 0 * * *',
'save_s3' => false,
]);
$backup->forceFill([
'last_execution_at' => now()->subDay(),
'missing_backup_notification_sent_at' => now(),
])->save();
$response = $this->withHeaders($this->headers)
->postJson("/api/v1/databases/{$database->uuid}/clone", [
@@ -148,11 +158,14 @@ describe('POST /api/v1/databases/{uuid}/clone', function () {
->assertJsonPath('message', 'Database cloned.');
$cloned = StandalonePostgresql::where('uuid', $response->json('uuid'))->first();
$clonedBackup = $cloned->scheduledBackups()->sole();
expect($cloned)->not->toBeNull()
->and($cloned->name)->toBe('cloned-db')
->and($cloned->environment_id)->toBe($database->environment_id)
->and($cloned->destination_id)->toBe($this->destination->id)
->and(str($cloned->status)->startsWith('exited'))->toBeTrue();
->and(str($cloned->status)->startsWith('exited'))->toBeTrue()
->and($clonedBackup->last_execution_at)->toBeNull()
->and($clonedBackup->missing_backup_notification_sent_at)->toBeNull();
});
test('creates renamed volumes when cloning a database with clone_volumes', function () {
@@ -11,6 +11,8 @@ use Illuminate\Support\Facades\Notification;
uses(RefreshDatabase::class);
afterEach(fn () => Carbon::setTestNow());
function missingBackupSchedule(Team $team, array $attributes = []): ScheduledDatabaseBackup
{
$backup = ScheduledDatabaseBackup::create(array_merge([