Skip to content

Commit 952aa9a

Browse files
authored
Merge pull request #5175 from Gog0/fix/wrong-container-name-for-database-proxy
fix wrong database container name + code simplification
2 parents a7318c2 + 078ef62 commit 952aa9a

File tree

4 files changed

+45
-62
lines changed

4 files changed

+45
-62
lines changed

app/Actions/Database/StartDatabaseProxy.php

+11-58
Original file line numberDiff line numberDiff line change
@@ -22,74 +22,27 @@ class StartDatabaseProxy
2222

2323
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|ServiceDatabase $database)
2424
{
25-
$internalPort = null;
26-
$type = $database->getMorphClass();
25+
$databaseType = $database->database_type;
2726
$network = data_get($database, 'destination.network');
2827
$server = data_get($database, 'destination.server');
2928
$containerName = data_get($database, 'uuid');
3029
$proxyContainerName = "{$database->uuid}-proxy";
3130
if ($database->getMorphClass() === \App\Models\ServiceDatabase::class) {
3231
$databaseType = $database->databaseType();
33-
// $connectPredefined = data_get($database, 'service.connect_to_docker_network');
3432
$network = $database->service->uuid;
3533
$server = data_get($database, 'service.destination.server');
3634
$proxyContainerName = "{$database->service->uuid}-proxy";
37-
switch ($databaseType) {
38-
case 'standalone-mariadb':
39-
$type = \App\Models\StandaloneMariadb::class;
40-
$containerName = "mariadb-{$database->service->uuid}";
41-
break;
42-
case 'standalone-mongodb':
43-
$type = \App\Models\StandaloneMongodb::class;
44-
$containerName = "mongodb-{$database->service->uuid}";
45-
break;
46-
case 'standalone-mysql':
47-
$type = \App\Models\StandaloneMysql::class;
48-
$containerName = "mysql-{$database->service->uuid}";
49-
break;
50-
case 'standalone-postgresql':
51-
$type = \App\Models\StandalonePostgresql::class;
52-
$containerName = "postgresql-{$database->service->uuid}";
53-
break;
54-
case 'standalone-redis':
55-
$type = \App\Models\StandaloneRedis::class;
56-
$containerName = "redis-{$database->service->uuid}";
57-
break;
58-
case 'standalone-keydb':
59-
$type = \App\Models\StandaloneKeydb::class;
60-
$containerName = "keydb-{$database->service->uuid}";
61-
break;
62-
case 'standalone-dragonfly':
63-
$type = \App\Models\StandaloneDragonfly::class;
64-
$containerName = "dragonfly-{$database->service->uuid}";
65-
break;
66-
case 'standalone-clickhouse':
67-
$type = \App\Models\StandaloneClickhouse::class;
68-
$containerName = "clickhouse-{$database->service->uuid}";
69-
break;
70-
case 'standalone-supabase/postgres':
71-
$type = \App\Models\StandalonePostgresql::class;
72-
$containerName = "supabase-db-{$database->service->uuid}";
73-
break;
74-
}
75-
}
76-
if ($type === \App\Models\StandaloneRedis::class) {
77-
$internalPort = 6379;
78-
} elseif ($type === \App\Models\StandalonePostgresql::class) {
79-
$internalPort = 5432;
80-
} elseif ($type === \App\Models\StandaloneMongodb::class) {
81-
$internalPort = 27017;
82-
} elseif ($type === \App\Models\StandaloneMysql::class) {
83-
$internalPort = 3306;
84-
} elseif ($type === \App\Models\StandaloneMariadb::class) {
85-
$internalPort = 3306;
86-
} elseif ($type === \App\Models\StandaloneKeydb::class) {
87-
$internalPort = 6379;
88-
} elseif ($type === \App\Models\StandaloneDragonfly::class) {
89-
$internalPort = 6379;
90-
} elseif ($type === \App\Models\StandaloneClickhouse::class) {
91-
$internalPort = 9000;
35+
$containerName = substr(str($database->name)->slug().'-'.$database->service->uuid, 0, 32);
9236
}
37+
$internalPort = match ($databaseType) {
38+
'standalone-mariadb', 'standalone-mysql' => 3306,
39+
'standalone-postgresql', 'standalone-supabase/postgres' => 5432,
40+
'standalone-redis', 'standalone-keydb', 'standalone-dragonfly' => 6379,
41+
'standalone-clickhouse' => 9000,
42+
'standalone-mongodb' => 27017,
43+
default => throw new \Exception("Unsupported database type: $databaseType"),
44+
};
45+
9346
$configuration_dir = database_proxy_dir($database->uuid);
9447
$nginxconf = <<<EOF
9548
user nginx;

app/Livewire/Project/Service/Database.php

+26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
use App\Actions\Database\StartDatabaseProxy;
66
use App\Actions\Database\StopDatabaseProxy;
7+
use App\Models\InstanceSettings;
78
use App\Models\ServiceDatabase;
9+
use Illuminate\Support\Facades\Auth;
10+
use Illuminate\Support\Facades\Hash;
811
use Livewire\Component;
912

1013
class Database extends Component
@@ -15,6 +18,8 @@ class Database extends Component
1518

1619
public $fileStorages;
1720

21+
public $parameters;
22+
1823
protected $listeners = ['refreshFileStorages'];
1924

2025
protected $rules = [
@@ -34,12 +39,33 @@ public function render()
3439

3540
public function mount()
3641
{
42+
$this->parameters = get_route_parameters();
3743
if ($this->database->is_public) {
3844
$this->db_url_public = $this->database->getServiceDatabaseUrl();
3945
}
4046
$this->refreshFileStorages();
4147
}
4248

49+
public function delete($password)
50+
{
51+
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
52+
if (! Hash::check($password, Auth::user()->password)) {
53+
$this->addError('password', 'The provided password is incorrect.');
54+
55+
return;
56+
}
57+
}
58+
59+
try {
60+
$this->database->delete();
61+
$this->dispatch('success', 'Database deleted.');
62+
63+
return redirect()->route('project.service.configuration', $this->parameters);
64+
} catch (\Throwable $e) {
65+
return handleError($e, $this);
66+
}
67+
}
68+
4369
public function instantSaveExclude()
4470
{
4571
$this->submit();

resources/views/livewire/project/service/database.blade.php

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<h2>{{ Str::headline($database->name) }}</h2>
88
@endif
99
<x-forms.button type="submit">Save</x-forms.button>
10+
<x-modal-confirmation title="Confirm Service Database Deletion?" buttonTitle="Delete" isErrorButton
11+
submitAction="delete" :actions="['The selected service database container will be stopped and permanently deleted.']" confirmationText="{{ Str::headline($database->name) }}"
12+
confirmationLabel="Please confirm the execution of the actions by entering the Service Database Name below"
13+
shortConfirmationLabel="Service Database Name" step3ButtonText="Permanently Delete" />
1014
</div>
1115
<div class="flex flex-col gap-2">
1216
<div class="flex gap-2">

resources/views/livewire/project/service/index.blade.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
<div class="flex flex-col h-full gap-8 pt-6 sm:flex-row">
44
<div class="flex flex-col items-start gap-2 min-w-fit">
55
<a class="menu-item"
6-
class="{{ request()->routeIs('project.service.configuration') ? 'menu-item-active' : '' }}"
7-
wire:navigate href="{{ route('project.service.configuration', [...$parameters, 'stack_service_uuid' => null]) }}">
6+
class="{{ request()->routeIs('project.service.configuration') ? 'menu-item-active' : '' }}" wire:navigate
7+
href="{{ route('project.service.configuration', [...$parameters, 'stack_service_uuid' => null]) }}">
88
<button><- Back</button>
99
</a>
1010
<a class="menu-item" :class="activeTab === 'general' && 'menu-item-active'"
1111
@click.prevent="activeTab = 'general'; window.location.hash = 'general'; if(window.location.search) window.location.search = ''"
1212
wire:navigate href="#">General</a>
1313
@if ($serviceDatabase?->isBackupSolutionAvailable())
1414
<a :class="activeTab === 'backups' && 'menu-item-active'" class="menu-item"
15-
@click.prevent="activeTab = 'backups'; window.location.hash = 'backups'"
16-
wire:navigate href="#backups">Backups</a>
15+
@click.prevent="activeTab = 'backups'; window.location.hash = 'backups'" wire:navigate
16+
href="#backups">Backups</a>
1717
@endif
1818
</div>
1919
<div class="w-full">

0 commit comments

Comments
 (0)