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.

feat(storage): group backups by database and filter by s3 status

Andras Bacsai86c8ec9c20b7
diff --git a/app/Livewire/Storage/Resources.php b/app/Livewire/Storage/Resources.php
index f171750130..30ac670660 100644
--- a/app/Livewire/Storage/Resources.php
+++ b/app/Livewire/Storage/Resources.php
@@ -13,11 +13,13 @@ class Resources extends Component
public function render()
{
$backups = ScheduledDatabaseBackup::where('s3_storage_id', $this->storage->id)
+ ->where('save_s3', true)
->with('database')
- ->get();
+ ->get()
+ ->groupBy(fn ($backup) => $backup->database_type.'-'.$backup->database_id);
return view('livewire.storage.resources', [
- 'backups' => $backups,
+ 'groupedBackups' => $backups,
]);
}
}
diff --git a/resources/views/livewire/storage/resources.blade.php b/resources/views/livewire/storage/resources.blade.php
index 29d26d4f53..4fdef1e4b6 100644
--- a/resources/views/livewire/storage/resources.blade.php
+++ b/resources/views/livewire/storage/resources.blade.php
@@ -1,62 +1,81 @@
<div>
- <div class="grid gap-4 lg:grid-cols-2">
- @forelse ($backups as $backup)
- @php
- $database = $backup->database;
- $databaseName = $database?->name ?? 'Deleted database';
- $link = null;
- if ($database && $database instanceof \App\Models\ServiceDatabase) {
- $service = $database->service;
- if ($service) {
- $environment = $service->environment;
- $project = $environment?->project;
- if ($project && $environment) {
- $link = route('project.service.configuration', [
- 'project_uuid' => $project->uuid,
- 'environment_uuid' => $environment->uuid,
- 'service_uuid' => $service->uuid,
- ]);
- }
- }
- } elseif ($database) {
- $environment = $database->environment;
+ @forelse ($groupedBackups as $backups)
+ @php
+ $firstBackup = $backups->first();
+ $database = $firstBackup->database;
+ $databaseName = $database?->name ?? 'Deleted database';
+ $resourceLink = null;
+ $backupParams = null;
+ if ($database && $database instanceof \App\Models\ServiceDatabase) {
+ $service = $database->service;
+ if ($service) {
+ $environment = $service->environment;
$project = $environment?->project;
if ($project && $environment) {
- $link = route('project.database.backup.index', [
+ $resourceLink = route('project.service.configuration', [
'project_uuid' => $project->uuid,
'environment_uuid' => $environment->uuid,
- 'database_uuid' => $database->uuid,
+ 'service_uuid' => $service->uuid,
]);
}
}
- @endphp
- @if ($link)
- <a {{ wireNavigate() }} href="{{ $link }}" @class(['gap-2 border cursor-pointer coolbox group'])>
- @else
- <div @class(['gap-2 border coolbox'])>
- @endif
- <div class="flex flex-col justify-center mx-6">
- <div class="box-title">
- {{ $databaseName }}
- </div>
- <div class="box-description">
- Frequency: {{ $backup->frequency }}
- </div>
- @if (!$backup->enabled)
- <span class="px-2 py-1 text-xs font-semibold text-yellow-800 bg-yellow-100 rounded dark:text-yellow-100 dark:bg-yellow-800 w-fit">
- Disabled
- </span>
+ } elseif ($database) {
+ $environment = $database->environment;
+ $project = $environment?->project;
+ if ($project && $environment) {
+ $resourceLink = route('project.database.backup.index', [
+ 'project_uuid' => $project->uuid,
+ 'environment_uuid' => $environment->uuid,
+ 'database_uuid' => $database->uuid,
+ ]);
+ $backupParams = [
+ 'project_uuid' => $project->uuid,
+ 'environment_uuid' => $environment->uuid,
+ 'database_uuid' => $database->uuid,
+ ];
+ }
+ }
+ @endphp
+ <div class="pb-6">
+ <div class="flex items-center gap-2 pb-2">
+ @if ($resourceLink)
+ <a {{ wireNavigate() }} href="{{ $resourceLink }}" class="text-lg font-bold dark:text-white hover:underline">{{ $databaseName }}</a>
+ @else
+ <span class="text-lg font-bold dark:text-white">{{ $databaseName }}</span>
+ @endif
+ </div>
+ <div class="grid gap-4 lg:grid-cols-2">
+ @foreach ($backups as $backup)
+ @php
+ $backupLink = null;
+ if ($backupParams) {
+ $backupLink = route('project.database.backup.execution', array_merge($backupParams, [
+ 'backup_uuid' => $backup->uuid,
+ ]));
+ }
+ @endphp
+ @if ($backupLink)
+ <a {{ wireNavigate() }} href="{{ $backupLink }}" @class(['gap-2 border cursor-pointer coolbox group'])>
+ @else
+ <div @class(['gap-2 border coolbox'])>
+ @endif
+ <div class="flex flex-col justify-center mx-6">
+ <div class="box-title">{{ $backup->frequency }}</div>
+ @if (!$backup->enabled)
+ <span class="px-2 py-1 text-xs font-semibold text-yellow-800 bg-yellow-100 rounded dark:text-yellow-100 dark:bg-yellow-800 w-fit">
+ Disabled
+ </span>
+ @endif
+ </div>
+ @if ($backupLink)
+ </a>
+ @else
+ </div>
@endif
- </div>
- @if ($link)
- </a>
- @else
- </div>
- @endif
- @empty
- <div>
- <div>No backup schedules are using this storage.</div>
+ @endforeach
</div>
- @endforelse
- </div>
+ </div>
+ @empty
+ <div>No backup schedules are using this storage.</div>
+ @endforelse
</div>
diff --git a/resources/views/livewire/storage/show.blade.php b/resources/views/livewire/storage/show.blade.php
index e54de37f30..0d580486e3 100644
--- a/resources/views/livewire/storage/show.blade.php
+++ b/resources/views/livewire/storage/show.blade.php
@@ -46,7 +46,7 @@
@if ($currentRoute === 'storage.show')
<livewire:storage.form :storage="$storage" />
@elseif ($currentRoute === 'storage.resources')
- <livewire:storage.resources :storage="$storage" />
+ <livewire:storage.resources :storage="$storage" :key="'resources-'.uniqid()" />
@endif
</div>
</div>