mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-25 17:01:49 -04:00
Merge remote-tracking branch 'origin/main' into next
This commit is contained in:
@@ -157,7 +157,9 @@ class Destination extends Component
|
||||
$network = StandaloneDocker::ownedByCurrentTeam()->where('server_id', $server->id)->findOrFail($network_id);
|
||||
$this->authorize('update', $this->resource);
|
||||
|
||||
$this->resource->additional_networks()->attach($network->id, ['server_id' => $server->id]);
|
||||
$this->resource->additional_networks()->syncWithoutDetaching([
|
||||
$network->id => ['server_id' => $server->id],
|
||||
]);
|
||||
$this->dispatch('refresh');
|
||||
} catch (\Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('additional_destinations')
|
||||
->select([
|
||||
'application_id',
|
||||
'server_id',
|
||||
'standalone_docker_id',
|
||||
DB::raw('MIN(id) as first_id'),
|
||||
])
|
||||
->groupBy('application_id', 'server_id', 'standalone_docker_id')
|
||||
->havingRaw('COUNT(*) > 1')
|
||||
->get()
|
||||
->each(function (object $duplicate): void {
|
||||
DB::table('additional_destinations')
|
||||
->where('application_id', $duplicate->application_id)
|
||||
->where('server_id', $duplicate->server_id)
|
||||
->where('standalone_docker_id', $duplicate->standalone_docker_id)
|
||||
->where('id', '!=', $duplicate->first_id)
|
||||
->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void {}
|
||||
};
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('additional_destinations', function (Blueprint $table) {
|
||||
$table->unique(
|
||||
['application_id', 'server_id', 'standalone_docker_id'],
|
||||
'additional_destinations_application_server_docker_unique'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('additional_destinations', function (Blueprint $table) {
|
||||
$table->dropUnique('additional_destinations_application_server_docker_unique');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -10,6 +10,7 @@ use App\Models\Server;
|
||||
use App\Models\StandaloneDocker;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
@@ -123,6 +124,31 @@ describe('Destination::addServer GHSA-j395-3pqh-9r5g', function () {
|
||||
expect($additional->first()->id)->toBe($this->destinationA2->id);
|
||||
expect($additional->first()->pivot->server_id)->toBe($this->serverA2->id);
|
||||
});
|
||||
|
||||
test('attaching the same server twice does not create duplicate destinations', function () {
|
||||
Livewire::test(Destination::class, ['resource' => $this->applicationA])
|
||||
->call('addServer', $this->destinationA2->id, $this->serverA2->id)
|
||||
->call('addServer', $this->destinationA2->id, $this->serverA2->id);
|
||||
|
||||
expect(DB::table('additional_destinations')
|
||||
->where('application_id', $this->applicationA->id)
|
||||
->where('standalone_docker_id', $this->destinationA2->id)
|
||||
->where('server_id', $this->serverA2->id)
|
||||
->count())->toBe(1);
|
||||
});
|
||||
|
||||
test('the database rejects duplicate application server destinations', function () {
|
||||
$destination = [
|
||||
'application_id' => $this->applicationA->id,
|
||||
'server_id' => $this->serverA2->id,
|
||||
'standalone_docker_id' => $this->destinationA2->id,
|
||||
];
|
||||
|
||||
DB::table('additional_destinations')->insert($destination);
|
||||
|
||||
expect(fn () => DB::table('additional_destinations')->insert($destination))
|
||||
->toThrow(QueryException::class);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Destination::promote GHSA-j395-3pqh-9r5g', function () {
|
||||
|
||||
Reference in New Issue
Block a user