Files
coolify/app/Livewire/Concerns/ManagesDatabaseBackup.php
T
Andras Bacsai fa1895c99a feat(dashboard): add canvas view with active deployment overlay
Add a /dashboard/canvas page that renders every team server with its
resources and their running or queued deployments, backed by a new
ServerCanvasController::dashboard endpoint and a per-server usage
endpoint for zone headers. The dashboard remembers the list/canvas
choice and each section (projects, servers) its own table/grid view.

- Show Deploying/Queued pills on canvas cards and a foldable recent
  deployments panel; add shared CanvasControls component
- Allow backup downloads from the server host via the S3 download
  storage (PrepareFileDownloadJob accepts a null container)
- Extract backup toggle/run actions into ManagesDatabaseBackup and
  surface them in backup execution headers; merge S3 and retention
  sections into the general backup settings
- Move deployments indicator to the top bar and add a main nav
  resource menu with submenus; simplify breadcrumbs and settings
  layouts
- Add shared variables overview canvas and scheduled task modals
- Add feature tests for dashboard canvas, view modes, navbar
  submenus, backup S3 downloads and scheduled task modals
2026-10-14 23:55:28 +02:00

86 lines
3.1 KiB
PHP

<?php
namespace App\Livewire\Concerns;
use App\Jobs\DatabaseBackupJob;
use App\Models\ScheduledDatabaseBackup;
use App\Models\ServiceDatabase;
use Illuminate\Http\RedirectResponse;
use Livewire\Features\SupportRedirects\Redirector;
trait ManagesDatabaseBackup
{
/**
* Turn the backup schedule on or off and return the new state.
*/
protected function toggleDatabaseBackup(ScheduledDatabaseBackup $backup): bool
{
$this->authorize('manageBackups', $backup->database);
$backup->enabled = ! $backup->enabled;
$changedFields = auditChangedFields($backup);
$backup->save();
$database = $backup->database;
auditLog('ui.database.backup_schedule_updated', [
'team_id' => $database?->team()?->id,
'database_uuid' => $database?->uuid,
'database_name' => $database?->name,
'backup_uuid' => $backup->uuid,
'changed_fields' => $changedFields,
]);
$this->dispatch('success', $backup->enabled ? 'Backup enabled.' : 'Backup disabled.');
return $backup->enabled;
}
/**
* Queue a backup run now and redirect to the executions page of the backup.
*/
protected function queueDatabaseBackup(ScheduledDatabaseBackup $backup): Redirector|RedirectResponse|null
{
$this->authorize('manageBackups', $backup->database);
$database = $backup->database->refresh();
if ($database->id !== 0 && ! str($database->status)->startsWith('running')) {
$this->dispatch('error', 'The database must be running to start a backup.');
return null;
}
DatabaseBackupJob::dispatch($backup);
auditLog('ui.database.backup_started', [
'team_id' => $database->team()?->id,
'database_uuid' => $database->uuid,
'database_name' => $database->name,
'backup_uuid' => $backup->uuid,
]);
$this->dispatch('success', 'Backup queued. It will be available in a few minutes.');
if ($database instanceof ServiceDatabase) {
return redirect()->route('project.service.database.backup.executions', [
'project_uuid' => $database->service->project()->uuid,
'environment_uuid' => $database->service->environment->uuid,
'service_uuid' => $database->service->uuid,
'stack_service_uuid' => $database->uuid,
'backup_uuid' => $backup->uuid,
]);
}
// Instance databases (e.g. coolify-db) have no project/environment.
// Stay on the current page (settings.backup) instead of redirecting.
$project = $database->project();
$environment = $database->environment;
if (! $project || ! $environment) {
return null;
}
return redirect()->route('project.database.backup.executions', [
'project_uuid' => $project->uuid,
'environment_uuid' => $environment->uuid,
'database_uuid' => $database->uuid,
'backup_uuid' => $backup->uuid,
]);
}
}