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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
Merge remote-tracking branch 'origin/next' into volume-backups-server-s3
Andras Bacsaiddbed9f8a655
diff --cc app/Livewire/Project/Database/CreateScheduledBackup.phpindex 0f37bf802b,49065711b2..e72277e800--- a/app/Livewire/Project/Database/CreateScheduledBackup.php+++ b/app/Livewire/Project/Database/CreateScheduledBackup.php@@@ -26,8 -48,28 +26,14 @@@ class CreateScheduledBackup extends Comtry {$this->authorize('manageBackups', $this->database);+ if (! $this->database->isBackupSolutionAvailable()) {+ $this->dispatch('error', 'Scheduled backups are not supported for this database type.');++ return;+ }+$this->validate();- if ($this->saveToS3) {- $s3StorageExists = ! is_null($this->s3StorageId)- && S3Storage::where('team_id', currentTeam()->id)- ->where('is_usable', true)- ->whereKey($this->s3StorageId)- ->exists();-- if (! $s3StorageExists) {- $this->dispatch('error', 'Please select a valid S3 storage to enable S3 backups.');-- return;- }- }-$isValid = validate_cron_expression($this->frequency);if (! $isValid) {$this->dispatch('error', 'Invalid Cron / Human expression.');diff --cc resources/views/livewire/project/database/backup-edit/general.blade.phpindex a9052118a9,0000000000..ba6102ee79mode 100644,000000..100644--- a/resources/views/livewire/project/database/backup-edit/general.blade.php+++ b/resources/views/livewire/project/database/backup-edit/general.blade.php@@@ -1,62 -1,0 +1,66 @@@+<form wire:submit="submit" class="flex flex-col gap-4">+ <div class="flex flex-col gap-3 sm:flex-row sm:items-center">+ <h2>General</h2>+ <div class="flex flex-col gap-2 sm:flex-row sm:flex-wrap">+ <x-forms.button type="submit" class="w-full sm:w-auto">Save</x-forms.button>+ @if (!$backupEnabled)+ <x-forms.button type="button" wire:click="toggleEnabled" wire:loading.attr="disabled"+ wire:target="toggleEnabled" isHighlighted>Enable Backup</x-forms.button>+ @else+ <x-forms.button type="button" wire:click="toggleEnabled" wire:loading.attr="disabled"+ wire:target="toggleEnabled">Disable Backup</x-forms.button>+ @endif+ @if (str($status)->startsWith('running'))+ <x-forms.button wire:click="backupNow" class="w-full sm:w-auto">Backup Now</x-forms.button>+ @endif+ </div>+ </div>++ <div class="flex flex-col gap-2">+ <div class="flex flex-col gap-2">+ @if ($backup->database_type === 'App\Models\StandalonePostgresql' && $backup->database_id !== 0)+ <div class="w-48">+ <x-forms.checkbox label="Backup All Databases" id="dumpAll" instantSave />+ </div>+ @if (!$backup->dump_all)+ <x-forms.input label="Databases To Backup"+ helper="Comma separated list of databases to backup. Empty will include the default one."+ id="databasesToBackup" />+ @endif+ @elseif ($backup->database_type === 'App\Models\StandaloneMongodb')+ <x-forms.input label="Databases To Include"+ helper="A list of databases to backup. You can specify which collection(s) per database to exclude from the backup. Empty will include all databases and collections.<br><br>Example:<br><br>database1:collection1,collection2|database2:collection3,collection4<br><br> database1 will include all collections except collection1 and collection2. <br>database2 will include all collections except collection3 and collection4.<br><br>Another Example:<br><br>database1:collection1|database2<br><br> database1 will include all collections except collection1.<br>database2 will include ALL collections."+ id="databasesToBackup" />+ @elseif ($backup->database_type === 'App\Models\StandaloneMysql')+ <div class="w-48">+ <x-forms.checkbox label="Backup All Databases" id="dumpAll" instantSave />+ </div>+ @if (!$backup->dump_all)+ <x-forms.input label="Databases To Backup"+ helper="Comma separated list of databases to backup. Empty will include the default one."+ id="databasesToBackup" />+ @endif+ @elseif ($backup->database_type === 'App\Models\StandaloneMariadb')+ <div class="w-48">+ <x-forms.checkbox label="Backup All Databases" id="dumpAll" instantSave />+ </div>+ @if (!$backup->dump_all)+ <x-forms.input label="Databases To Backup"+ helper="Comma separated list of databases to backup. Empty will include the default one."+ id="databasesToBackup" />+ @endif++ @elseif ($backup->database_type === 'App\Models\StandaloneClickhouse')++ <x-forms.input label="Databases To Backup"++ helper="Comma separated list of databases to backup. Empty will include the default one."++ id="databasesToBackup" />+ @endif+ </div>+ <div class="grid grid-cols-1 gap-2 md:grid-cols-3">+ <x-forms.input label="Frequency" id="frequency" required />+ <x-forms.input label="Timezone" id="timezone" disabled+ helper="The timezone of the server where the backup is scheduled to run (if not set, the instance timezone will be used)" required />+ <x-forms.input label="Timeout" id="timeout" type="number" min="60"+ helper="The timeout of the backup job in seconds." required />+ </div>+ </div>+</form>diff --cc resources/views/livewire/project/database/heading.blade.phpindex bae7151e37,66af4895f4..78b533ec0f--- a/resources/views/livewire/project/database/heading.blade.php+++ b/resources/views/livewire/project/database/heading.blade.php@@@ -5,16 -5,11 +5,11 @@@['label' => 'Backups','route' => 'project.database.backup.index',- 'active' => request()->routeIs('project.database.backup.index', 'project.database.backup.execution'),+ 'active' => request()->routeIs('project.database.backup.*'),- 'visible' => in_array($database->getMorphClass(), [- 'App\Models\StandalonePostgresql',- 'App\Models\StandaloneMongodb',- 'App\Models\StandaloneMysql',- 'App\Models\StandaloneMariadb',- ]),+ 'visible' => $database->isBackupSolutionAvailable(),],+ ['label' => 'Logs', 'route' => 'project.database.logs', 'active' => request()->routeIs('project.database.logs')],+ ['label' => 'Terminal', 'route' => 'project.database.command', 'active' => request()->routeIs('project.database.command'), 'navigate' => false, 'visible' => auth()->user()?->can('canAccessTerminal')],];$databaseConfigurationItems = [@@@ -190,16 -185,6 +185,12 @@@Configuration</a>- @if (- $database->getMorphClass() === 'App\Models\StandalonePostgresql' ||- $database->getMorphClass() === 'App\Models\StandaloneMongodb' ||- $database->getMorphClass() === 'App\Models\StandaloneMysql' ||- $database->getMorphClass() === 'App\Models\StandaloneMariadb')++ @if ($database->isBackupSolutionAvailable())+ <a class="shrink-0 {{ request()->routeIs('project.database.backup.*') ? 'dark:text-white' : '' }}" {{ wireNavigate() }}+ href="{{ route('project.database.backup.index', $parameters) }}">+ Backups+ </a>+ @endif<a class="shrink-0 {{ request()->routeIs('project.database.logs') ? 'dark:text-white' : '' }}"href="{{ route('project.database.logs', $parameters) }}">Logs@@@ -210,6 -195,12 +201,7 @@@Terminal</a>@endcan- @if ($database->isBackupSolutionAvailable())- <a class="shrink-0 {{ request()->routeIs('project.database.backup.index') ? 'dark:text-white' : '' }}" {{ wireNavigate() }}- href="{{ route('project.database.backup.index', $parameters) }}">- Backups- </a>- @endif++</nav>@if ($database->destination->server->isFunctional())diff --cc tests/Feature/CreateScheduledBackupValidationTest.phpindex bb46f8f784,56a4cf479f..3a5ea6a37e--- a/tests/Feature/CreateScheduledBackupValidationTest.php+++ b/tests/Feature/CreateScheduledBackupValidationTest.php@@@ -3,12 -3,13 +3,14 @@@use App\Livewire\Project\Database\CreateScheduledBackup;use App\Models\Environment;use App\Models\Project;-use App\Models\S3Storage;use App\Models\ScheduledDatabaseBackup;use App\Models\Server;+use App\Models\Service;+use App\Models\ServiceDatabase;+ use App\Models\StandaloneClickhouse;use App\Models\StandaloneDocker;use App\Models\StandalonePostgresql;+ use App\Models\StandaloneRedis;use App\Models\Team;use App\Models\User;use Illuminate\Foundation\Testing\RefreshDatabase;@@@ -22,72 -56,131 +24,124 @@@ beforeEach(function ()$this->user->teams()->attach($this->team, ['role' => 'owner']);$this->actingAs($this->user);session(['currentTeam' => $this->team]);-});--it('rejects enabling S3 backup without a selected S3 storage', function () {- $database = createDatabaseForScheduledBackupTest($this->team);- Livewire::test(CreateScheduledBackup::class, ['database' => $database])- ->set('frequency', '0 0 * * *')- ->set('saveToS3', true)- ->set('s3StorageId', null)- ->call('submit')- ->assertDispatched('error');-- expect(ScheduledDatabaseBackup::count())->toBe(0);-});--it('rejects an S3 storage not owned by the current team', function () {- $database = createDatabaseForScheduledBackupTest($this->team);-- $foreignS3 = createS3StorageForTeam(Team::factory()->create(), 'Foreign S3');-- Livewire::test(CreateScheduledBackup::class, ['database' => $database])- ->set('frequency', '0 0 * * *')- ->set('saveToS3', true)- ->set('s3StorageId', $foreignS3->id)- ->call('submit')- ->assertDispatched('error');-- expect(ScheduledDatabaseBackup::count())->toBe(0);+ $this->server = Server::factory()->create(['team_id' => $this->team->id]);+ $this->destination = StandaloneDocker::where('server_id', $this->server->id)->firstOrFail();+ $this->project = Project::factory()->create(['team_id' => $this->team->id]);+ $this->environment = Environment::factory()->create(['project_id' => $this->project->id]);});-it('rejects an S3 storage that is reassigned after the component is mounted', function () {- $database = createDatabaseForScheduledBackupTest($this->team);- $s3 = createS3StorageForTeam($this->team);+it('creates a standalone database backup without S3 and opens its configuration', function () {+ $database = StandalonePostgresql::create([+ 'name' => 'postgres',+ 'image' => 'postgres:16-alpine',+ 'postgres_user' => 'postgres',+ 'postgres_password' => 'password',+ 'postgres_db' => 'postgres',+ 'environment_id' => $this->environment->id,+ 'destination_id' => $this->destination->id,+ 'destination_type' => $this->destination->getMorphClass(),+ ]);$component = Livewire::test(CreateScheduledBackup::class, ['database' => $database])- ->set('frequency', '0 0 * * *')- ->set('saveToS3', true)- ->set('s3StorageId', $s3->id);+ ->assertDontSee('Save to S3')+ ->set('frequency', 'daily')+ ->call('submit');- $s3->update(['team_id' => Team::factory()->create()->id]);+ $backup = ScheduledDatabaseBackup::query()->sole();- $component- ->call('submit')- ->assertDispatched('error');+ $component->assertRedirectToRoute('project.database.backup.execution', [+ 'project_uuid' => $this->project->uuid,+ 'environment_uuid' => $this->environment->uuid,+ 'database_uuid' => $database->uuid,+ 'backup_uuid' => $backup->uuid,+ ]);- expect(ScheduledDatabaseBackup::count())->toBe(0);+ expect($backup->save_s3)->toBeFalsy()+ ->and($backup->s3_storage_id)->toBeNull();});-it('rejects an S3 storage that becomes unusable after the component is mounted', function () {- $database = createDatabaseForScheduledBackupTest($this->team);- $s3 = createS3StorageForTeam($this->team);+it('creates a service database backup without S3 and opens its configuration', function () {+ $service = Service::factory()->create([+ 'server_id' => $this->server->id,+ 'destination_id' => $this->destination->id,+ 'destination_type' => $this->destination->getMorphClass(),+ 'environment_id' => $this->environment->id,+ ]);+ $database = ServiceDatabase::create([+ 'service_id' => $service->id,+ 'name' => 'postgres',+ 'image' => 'postgres:16-alpine',+ 'custom_type' => 'postgresql',+ ]);$component = Livewire::test(CreateScheduledBackup::class, ['database' => $database])- ->set('frequency', '0 0 * * *')- ->set('saveToS3', true)- ->set('s3StorageId', $s3->id);-- $s3->update(['is_usable' => false]);-- $component- ->call('submit')- ->assertDispatched('error');-- expect(ScheduledDatabaseBackup::count())->toBe(0);-});+ ->assertDontSee('Save to S3')+ ->set('frequency', 'daily')+ ->call('submit');-it('creates a scheduled backup with a valid team-owned S3 storage', function () {- $database = createDatabaseForScheduledBackupTest($this->team);- $s3 = createS3StorageForTeam($this->team);+ $backup = ScheduledDatabaseBackup::query()->sole();- Livewire::test(CreateScheduledBackup::class, ['database' => $database])- ->set('frequency', '0 0 * * *')- ->set('saveToS3', true)- ->set('s3StorageId', $s3->id)- ->call('submit')- ->assertDispatched('refreshScheduledBackups');+ $component->assertRedirectToRoute('project.service.database.backup.show', [+ 'project_uuid' => $this->project->uuid,+ 'environment_uuid' => $this->environment->uuid,+ 'service_uuid' => $service->uuid,+ 'stack_service_uuid' => $database->uuid,+ 'backup_uuid' => $backup->uuid,+ ]);- $backup = ScheduledDatabaseBackup::first();- expect($backup)->not->toBeNull();- expect($backup->save_s3)->toBeTruthy();- expect($backup->s3_storage_id)->toBe($s3->id);+ expect($backup->save_s3)->toBeFalsy()+ ->and($backup->s3_storage_id)->toBeNull();});++ it('creates a clickhouse backup for its configured database', function () {+ $server = Server::factory()->create(['team_id' => $this->team->id]);+ $destination = StandaloneDocker::where('server_id', $server->id)->firstOrFail();+ $project = Project::factory()->create(['team_id' => $this->team->id]);+ $environment = Environment::factory()->create(['project_id' => $project->id]);+ $database = StandaloneClickhouse::create([+ 'name' => 'clickhouse-scheduled-backup',+ 'clickhouse_admin_user' => 'default',+ 'clickhouse_admin_password' => 'password',+ 'clickhouse_db' => 'analytics',+ 'environment_id' => $environment->id,+ 'destination_id' => $destination->id,+ 'destination_type' => $destination->getMorphClass(),+ ]);+- Livewire::test(CreateScheduledBackup::class, ['database' => $database])++ $component = Livewire::test(CreateScheduledBackup::class, ['database' => $database])+ ->set('frequency', 'daily')- ->call('submit')- ->assertDispatched('refreshScheduledBackups');++ ->call('submit');++ $backup = ScheduledDatabaseBackup::firstOrFail();+++ $component->assertRedirectToRoute('project.database.backup.execution', [++ 'project_uuid' => $project->uuid,++ 'environment_uuid' => $environment->uuid,++ 'database_uuid' => $database->uuid,++ 'backup_uuid' => $backup->uuid,++ ]);+++ expect($backup->database_type)->toBe(StandaloneClickhouse::class)+ ->and($backup->databases_to_backup)->toBe('analytics');+ });++ it('rejects scheduled backups for unsupported database types', function () {+ $server = Server::factory()->create(['team_id' => $this->team->id]);+ $destination = StandaloneDocker::where('server_id', $server->id)->firstOrFail();+ $project = Project::factory()->create(['team_id' => $this->team->id]);+ $environment = Environment::factory()->create(['project_id' => $project->id]);+ $database = StandaloneRedis::create([+ 'name' => 'redis-without-backups',+ 'environment_id' => $environment->id,+ 'destination_id' => $destination->id,+ 'destination_type' => $destination->getMorphClass(),+ ]);++ Livewire::test(CreateScheduledBackup::class, ['database' => $database])+ ->set('frequency', 'daily')+ ->call('submit')+ ->assertDispatched('error');++ expect(ScheduledDatabaseBackup::count())->toBe(0);+ });