2026-01-02 15:29:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire\Project\Service;
|
|
|
|
|
|
2026-07-15 15:34:22 +00:00
|
|
|
use App\Models\ScheduledDatabaseBackup;
|
2026-01-02 15:29:48 +00:00
|
|
|
use App\Models\Service;
|
|
|
|
|
use App\Models\ServiceDatabase;
|
|
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class DatabaseBackups extends Component
|
|
|
|
|
{
|
|
|
|
|
use AuthorizesRequests;
|
|
|
|
|
|
|
|
|
|
public ?Service $service = null;
|
|
|
|
|
|
|
|
|
|
public ?ServiceDatabase $serviceDatabase = null;
|
|
|
|
|
|
|
|
|
|
public array $parameters;
|
|
|
|
|
|
2026-07-15 15:34:22 +00:00
|
|
|
public array $backupParameters = [];
|
|
|
|
|
|
2026-01-02 15:29:48 +00:00
|
|
|
public array $query;
|
|
|
|
|
|
|
|
|
|
public bool $isImportSupported = false;
|
|
|
|
|
|
2026-07-15 15:34:22 +00:00
|
|
|
public ?ScheduledDatabaseBackup $backup = null;
|
|
|
|
|
|
|
|
|
|
public string $section = 'index';
|
|
|
|
|
|
|
|
|
|
public $s3s;
|
|
|
|
|
|
2026-01-02 15:29:48 +00:00
|
|
|
protected $listeners = ['refreshScheduledBackups' => '$refresh'];
|
|
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2026-07-15 15:34:22 +00:00
|
|
|
$this->parameters = array_filter(
|
|
|
|
|
get_route_parameters(),
|
|
|
|
|
fn (string $key): bool => $key !== 'backup_uuid',
|
|
|
|
|
ARRAY_FILTER_USE_KEY,
|
|
|
|
|
);
|
2026-01-02 15:29:48 +00:00
|
|
|
$this->query = request()->query();
|
2026-05-22 11:38:28 +00:00
|
|
|
$project = currentTeam()
|
|
|
|
|
->projects()
|
|
|
|
|
->select('id', 'uuid', 'team_id')
|
|
|
|
|
->where('uuid', $this->parameters['project_uuid'])
|
|
|
|
|
->firstOrFail();
|
|
|
|
|
$environment = $project->environments()
|
|
|
|
|
->select('id', 'uuid', 'name', 'project_id')
|
|
|
|
|
->where('uuid', $this->parameters['environment_uuid'])
|
|
|
|
|
->firstOrFail();
|
|
|
|
|
$this->service = $environment->services()->whereUuid($this->parameters['service_uuid'])->firstOrFail();
|
2026-01-02 15:29:48 +00:00
|
|
|
$this->authorize('view', $this->service);
|
|
|
|
|
|
|
|
|
|
$this->serviceDatabase = $this->service->databases()->whereUuid($this->parameters['stack_service_uuid'])->first();
|
|
|
|
|
if (! $this->serviceDatabase) {
|
|
|
|
|
return redirect()->route('project.service.configuration', [
|
|
|
|
|
'project_uuid' => $this->parameters['project_uuid'],
|
|
|
|
|
'environment_uuid' => $this->parameters['environment_uuid'],
|
|
|
|
|
'service_uuid' => $this->parameters['service_uuid'],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if backups are supported for this database
|
|
|
|
|
if (! $this->serviceDatabase->isBackupSolutionAvailable() && ! $this->serviceDatabase->is_migrated) {
|
|
|
|
|
return redirect()->route('project.service.index', $this->parameters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if import is supported for this database type
|
|
|
|
|
$dbType = $this->serviceDatabase->databaseType();
|
|
|
|
|
$supportedTypes = ['mysql', 'mariadb', 'postgres', 'mongo'];
|
|
|
|
|
$this->isImportSupported = collect($supportedTypes)->contains(fn ($type) => str_contains($dbType, $type));
|
2026-07-15 15:34:22 +00:00
|
|
|
|
|
|
|
|
if (request()->route('backup_uuid')) {
|
|
|
|
|
$this->backup = $this->serviceDatabase->scheduledBackups()
|
|
|
|
|
->where('uuid', request()->route('backup_uuid'))
|
|
|
|
|
->firstOrFail();
|
|
|
|
|
$this->s3s = currentTeam()->s3s;
|
|
|
|
|
$this->backupParameters = [...$this->parameters, 'backup_uuid' => $this->backup->uuid];
|
|
|
|
|
$this->section = match (request()->route()?->getName()) {
|
|
|
|
|
'project.service.database.backup.s3' => 's3',
|
|
|
|
|
'project.service.database.backup.retention' => 'retention',
|
|
|
|
|
'project.service.database.backup.executions' => 'executions',
|
|
|
|
|
'project.service.database.backup.danger' => 'danger',
|
|
|
|
|
default => 'general',
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-01-02 15:29:48 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
return view('livewire.project.service.database-backups');
|
|
|
|
|
}
|
|
|
|
|
}
|