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
fix(api): match database backup configs by database type and id
Andras Bacsai0b581454cfc1
diff --git a/app/Http/Controllers/Api/DatabasesController.php b/app/Http/Controllers/Api/DatabasesController.phpindex 652871e89b..91c68d6e4c 100644--- a/app/Http/Controllers/Api/DatabasesController.php+++ b/app/Http/Controllers/Api/DatabasesController.php@@ -279,10 +279,10 @@ class DatabasesController extends Controller$backupConfigs = ScheduledDatabaseBackup::ownedByCurrentTeamAPI($teamId)->with('latest_log')->whereIn('database_id', $databaseIds)->get()- ->groupBy('database_id');+ ->groupBy(fn (ScheduledDatabaseBackup $backup) => $backup->database_type.':'.$backup->database_id);$databases = $databases->map(function ($database) use ($backupConfigs) {- $database->backup_configs = $backupConfigs->get($database->id, collect())->values();+ $database->backup_configs = $backupConfigs->get($database->getMorphClass().':'.$database->id, collect())->values();return $this->removeSensitiveData($database);});diff --git a/tests/Feature/Api/DatabaseListBackupConfigsApiTest.php b/tests/Feature/Api/DatabaseListBackupConfigsApiTest.phpnew file mode 100644index 0000000000..069db4a75b--- /dev/null+++ b/tests/Feature/Api/DatabaseListBackupConfigsApiTest.php@@ -0,0 +1,74 @@+<?php++use App\Models\Environment;+use App\Models\InstanceSettings;+use App\Models\Project;+use App\Models\ScheduledDatabaseBackup;+use App\Models\Server;+use App\Models\StandaloneMysql;+use App\Models\StandalonePostgresql;+use App\Models\Team;+use App\Models\User;+use Illuminate\Foundation\Testing\RefreshDatabase;++uses(RefreshDatabase::class);++beforeEach(function () {+ Server::flushIdentityMap();+ InstanceSettings::forceCreate(['id' => 0, 'is_api_enabled' => true]);++ $this->team = Team::factory()->create();+ $this->user = User::factory()->create();+ $this->team->members()->attach($this->user->id, ['role' => 'owner']);+ session(['currentTeam' => $this->team]);+ $token = $this->user->createToken('database-list-backups', ['read']);+ $token->accessToken->forceFill(['team_id' => $this->team->id])->save();+ $this->bearerToken = $token->plainTextToken;++ $server = Server::factory()->create(['team_id' => $this->team->id]);+ $destination = $server->standaloneDockers()->firstOrFail();+ $project = Project::factory()->create(['team_id' => $this->team->id]);+ $environment = Environment::factory()->create(['project_id' => $project->id]);+ $placement = [+ 'environment_id' => $environment->id,+ 'destination_id' => $destination->id,+ 'destination_type' => $destination->getMorphClass(),+ ];++ $this->postgres = StandalonePostgresql::create([+ 'name' => 'shared-id-postgres',+ 'postgres_user' => 'postgres',+ 'postgres_password' => 'password',+ 'postgres_db' => 'app',+ 'image' => 'postgres:16-alpine',+ ...$placement,+ ]);+ $this->mysql = StandaloneMysql::forceCreate([+ 'id' => $this->postgres->id,+ 'name' => 'shared-id-mysql',+ 'mysql_root_password' => 'password',+ 'mysql_password' => 'password',+ 'mysql_user' => 'mysql',+ 'mysql_database' => 'app',+ 'image' => 'mysql:8',+ ...$placement,+ ]);+});++test('database list matches backup configs by database type and id', function () {+ $backup = ScheduledDatabaseBackup::create([+ 'frequency' => '0 0 * * *',+ 'database_type' => $this->postgres->getMorphClass(),+ 'database_id' => $this->postgres->id,+ 'team_id' => $this->team->id,+ ]);++ $databases = collect(+ $this->withToken($this->bearerToken)->getJson('/api/v1/databases')->assertOk()->json()+ )->keyBy('uuid');++ expect($this->mysql->id)->toBe($this->postgres->id)+ ->and($databases[$this->postgres->uuid]['backup_configs'])->toHaveCount(1)+ ->and($databases[$this->postgres->uuid]['backup_configs'][0]['uuid'])->toBe($backup->uuid)+ ->and($databases[$this->mysql->uuid]['backup_configs'])->toBe([]);+});