From b20510a8b148e1ca8d89a55ff6e5d32c592a88e1 Mon Sep 17 00:00:00 2001 From: Mahad Kalam Date: Wed, 10 Dec 2025 19:48:27 +0000 Subject: [PATCH] CodeRabbit fixes, again. --- app/Jobs/DatabaseBackupJob.php | 3 +- app/Jobs/PgBackrestRestoreJob.php | 2 +- app/Livewire/Project/Database/BackupEdit.php | 31 +++++++++++++------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/Jobs/DatabaseBackupJob.php b/app/Jobs/DatabaseBackupJob.php index 0d6b348fe..ba53effa7 100644 --- a/app/Jobs/DatabaseBackupJob.php +++ b/app/Jobs/DatabaseBackupJob.php @@ -26,6 +26,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; +use RuntimeException; use Throwable; use Visus\Cuid2\Cuid2; @@ -822,7 +823,7 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue $config = PgBackrestService::generateConfig($this->database); if ($config === null) { - throw new \Exception('No valid pgBackRest repository configured. Please configure at least one repository (local or S3).'); + throw new RuntimeException('No valid pgBackRest repository configured. Please configure at least one repository (local or S3).'); } $configBase64 = base64_encode($config); diff --git a/app/Jobs/PgBackrestRestoreJob.php b/app/Jobs/PgBackrestRestoreJob.php index 23683c3db..602cb261c 100644 --- a/app/Jobs/PgBackrestRestoreJob.php +++ b/app/Jobs/PgBackrestRestoreJob.php @@ -400,7 +400,7 @@ class PgBackrestRestoreJob implements ShouldBeEncrypted, ShouldQueue $sidecarName = 'pgbackrest-restore-'.$this->database->uuid.'-'.time(); - $fullRestoreScript = $this->getInstallAndRunCommand($restoreCmd).' && chown -R 999:999 '.PgBackrestService::PGDATA_PATH; + $fullRestoreScript = $this->getInstallAndRunCommand($restoreCmd); $cmd = sprintf( 'docker run --rm --name %s --network %s %s %s %s sh -c \'%s\' 2>&1', diff --git a/app/Livewire/Project/Database/BackupEdit.php b/app/Livewire/Project/Database/BackupEdit.php index 275be6547..6cede88dc 100644 --- a/app/Livewire/Project/Database/BackupEdit.php +++ b/app/Livewire/Project/Database/BackupEdit.php @@ -9,6 +9,7 @@ use App\Models\StandalonePostgresql; use Exception; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Livewire\Attributes\Locked; use Livewire\Attributes\Validate; @@ -133,6 +134,14 @@ class BackupEdit extends Component */ public function togglePgbackrestEngine(): void { + $this->authorize('update', $this->backup->database); + + if (! $this->isPostgresql()) { + $this->engine = 'native'; + + return; + } + $this->engine = $this->engine === 'pgbackrest' ? 'native' : 'pgbackrest'; } @@ -157,18 +166,20 @@ class BackupEdit extends Component $this->backup->timeout = $this->timeout; if ($this->engine === 'pgbackrest') { - $this->backup->save_s3 = $this->saveS3; - $this->backup->disable_local_backup = $this->saveS3 && $this->disableLocalBackup; + DB::transaction(function () { + $this->backup->save_s3 = $this->saveS3; + $this->backup->disable_local_backup = $this->saveS3 && $this->disableLocalBackup; - $this->backup->pgbackrest_backup_type = $this->pgbackrestBackupType; - $this->backup->pgbackrest_compress_type = $this->pgbackrestCompressType; - $this->backup->pgbackrest_compress_level = $this->pgbackrestCompressLevel; - $this->backup->pgbackrest_log_level = $this->pgbackrestLogLevel; - $this->backup->pgbackrest_archive_mode = $this->pgbackrestArchiveMode; + $this->backup->pgbackrest_backup_type = $this->pgbackrestBackupType; + $this->backup->pgbackrest_compress_type = $this->pgbackrestCompressType; + $this->backup->pgbackrest_compress_level = $this->pgbackrestCompressLevel; + $this->backup->pgbackrest_log_level = $this->pgbackrestLogLevel; + $this->backup->pgbackrest_archive_mode = $this->pgbackrestArchiveMode; - $this->customValidate(); - $this->backup->save(); - $this->syncPgbackrestRepos(); + $this->customValidate(); + $this->backup->save(); + $this->syncPgbackrestRepos(); + }); } else { $this->backup->save_s3 = $this->saveS3; $this->backup->disable_local_backup = $this->disableLocalBackup;