From 14f86cd094d1ae46d03f0697451266c07d4b59e4 Mon Sep 17 00:00:00 2001
From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com>
Date: Thu, 20 Aug 2026 20:23:54 +0200
Subject: [PATCH] fix(backups): preserve backup state when cloning databases
---
app/Http/Controllers/Api/DatabasesController.php | 2 ++
.../database/backup-edit/general.blade.php | 2 +-
tests/Feature/Api/LifecycleApisTest.php | 15 ++++++++++++++-
.../MissingDatabaseBackupNotificationTest.php | 2 ++
4 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/app/Http/Controllers/Api/DatabasesController.php b/app/Http/Controllers/Api/DatabasesController.php
index 6ee1d7a014..1240a7160e 100644
--- a/app/Http/Controllers/Api/DatabasesController.php
+++ b/app/Http/Controllers/Api/DatabasesController.php
@@ -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,
diff --git a/resources/views/livewire/project/database/backup-edit/general.blade.php b/resources/views/livewire/project/database/backup-edit/general.blade.php
index 55faba19d3..5dddec8edd 100644
--- a/resources/views/livewire/project/database/backup-edit/general.blade.php
+++ b/resources/views/livewire/project/database/backup-edit/general.blade.php
@@ -92,7 +92,7 @@
diff --git a/tests/Feature/Api/LifecycleApisTest.php b/tests/Feature/Api/LifecycleApisTest.php
index 913eac59a5..f1cc10474e 100644
--- a/tests/Feature/Api/LifecycleApisTest.php
+++ b/tests/Feature/Api/LifecycleApisTest.php
@@ -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 () {
diff --git a/tests/Feature/MissingDatabaseBackupNotificationTest.php b/tests/Feature/MissingDatabaseBackupNotificationTest.php
index 28830fd5fd..f4f2efd191 100644
--- a/tests/Feature/MissingDatabaseBackupNotificationTest.php
+++ b/tests/Feature/MissingDatabaseBackupNotificationTest.php
@@ -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([