Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(backup): save removed databases in the databases to back up list

Andras Bacsai8429b6e94bff
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 dfe465e07a..56cf82e507 100644
--- a/resources/views/livewire/project/database/backup-edit/general.blade.php
+++ b/resources/views/livewire/project/database/backup-edit/general.blade.php
@@ -34,7 +34,7 @@
]" />
@if (! $backup->dump_all)
<div class="w-full" x-data="{
- value: @entangle('databasesToBackup').live,
+ value: @entangle('databasesToBackup'),
draft: '',
get databases() {
return (this.value || '').split(',').map(name => name.trim()).filter(Boolean);
diff --git a/tests/v4/Browser/DatabaseBackupDatabasesToBackupTest.php b/tests/v4/Browser/DatabaseBackupDatabasesToBackupTest.php
new file mode 100644
index 0000000000..601e69e9a9
--- /dev/null
+++ b/tests/v4/Browser/DatabaseBackupDatabasesToBackupTest.php
@@ -0,0 +1,53 @@
+<?php
+
+use App\Models\ScheduledDatabaseBackup;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+
+uses(RefreshDatabase::class);
+
+beforeEach(function () {
+ $this->stack = seedBrowserResourceStack();
+ $this->postgres = createBrowserPostgresql($this->stack, [
+ 'uuid' => 'db-browser-backup-pg',
+ 'name' => 'Backup Postgres',
+ ]);
+ $this->backup = ScheduledDatabaseBackup::create([
+ 'frequency' => '0 0 * * *',
+ 'save_s3' => false,
+ 'dump_all' => false,
+ 'databases_to_backup' => 'postgres,app',
+ 'database_type' => $this->postgres->getMorphClass(),
+ 'database_id' => $this->postgres->id,
+ 'team_id' => 0,
+ ]);
+});
+
+it('saves a removed database from the databases to back up', function () {
+ loginAndSkipBoarding();
+
+ $base = databaseConfigurationUrl($this->stack['project'], $this->stack['environment'], $this->postgres);
+
+ visit("{$base}/backups/{$this->backup->uuid}")
+ ->assertSee('Databases to back up')
+ ->click('[aria-label="Remove postgres"]')
+ ->click('Save changes')
+ ->assertSee('Backup updated successfully.')
+ ->screenshot(filename: 'database-backup-remove-database');
+
+ expect($this->backup->fresh()->databases_to_backup)->toBe('app');
+});
+
+it('saves an added database to the databases to back up', function () {
+ loginAndSkipBoarding();
+
+ $base = databaseConfigurationUrl($this->stack['project'], $this->stack['environment'], $this->postgres);
+
+ visit("{$base}/backups/{$this->backup->uuid}")
+ ->assertSee('Databases to back up')
+ ->fill('[placeholder="Type a database and press Enter"]', 'analytics')
+ ->keys('[placeholder="Type a database and press Enter"]', 'Enter')
+ ->assertSee('Backup updated successfully.')
+ ->screenshot(filename: 'database-backup-add-database');
+
+ expect($this->backup->fresh()->databases_to_backup)->toBe('postgres,app,analytics');
+});