diff --git a/app/Livewire/Project/New/Select.php b/app/Livewire/Project/New/Select.php index b25290f71..3c5f3901b 100644 --- a/app/Livewire/Project/New/Select.php +++ b/app/Livewire/Project/New/Select.php @@ -45,6 +45,8 @@ class Select extends Component public ?string $selectedEnvironment = null; + public string $postgresql_type = 'postgres:16-alpine'; + public ?string $existingPostgresqlUrl = null; public ?string $search = null; @@ -202,6 +204,8 @@ class Select extends Component $docker = $this->standaloneDockers->first() ?? $this->swarmDockers->first(); if ($docker) { $this->setDestination($docker->uuid); + + return $this->whatToDoNext(); } } $this->current_step = 'destinations'; @@ -211,15 +215,38 @@ class Select extends Component { $this->destination_uuid = $destination_uuid; + return $this->whatToDoNext(); + } + + public function setPostgresqlType(string $type) + { + $this->postgresql_type = $type; + return redirect()->route('project.resource.create', [ 'project_uuid' => $this->parameters['project_uuid'], 'environment_name' => $this->parameters['environment_name'], 'type' => $this->type, 'destination' => $this->destination_uuid, 'server_id' => $this->server_id, + 'database_image' => $this->postgresql_type, ]); } + public function whatToDoNext() + { + if ($this->type === 'postgresql') { + $this->current_step = 'select-postgresql-type'; + } else { + return redirect()->route('project.resource.create', [ + 'project_uuid' => $this->parameters['project_uuid'], + 'environment_name' => $this->parameters['environment_name'], + 'type' => $this->type, + 'destination' => $this->destination_uuid, + 'server_id' => $this->server_id, + ]); + } + } + public function loadServers() { $this->servers = Server::isUsable()->get(); diff --git a/app/Livewire/Project/Resource/Create.php b/app/Livewire/Project/Resource/Create.php index 341dd93d8..ba33e2f08 100644 --- a/app/Livewire/Project/Resource/Create.php +++ b/app/Livewire/Project/Resource/Create.php @@ -18,7 +18,8 @@ class Create extends Component $type = str(request()->query('type')); $destination_uuid = request()->query('destination'); $server_id = request()->query('server_id'); - + $database_image = request()->query('database_image'); + ray($database_image); $project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first(); if (! $project) { return redirect()->route('dashboard'); @@ -33,7 +34,11 @@ class Create extends Component if (in_array($type, DATABASE_TYPES)) { if ($type->value() === 'postgresql') { - $database = create_standalone_postgresql($environment->id, $destination_uuid); + $database = create_standalone_postgresql( + environmentId: $environment->id, + destinationUuid: $destination_uuid, + databaseImage: $database_image + ); } elseif ($type->value() === 'redis') { $database = create_standalone_redis($environment->id, $destination_uuid); } elseif ($type->value() === 'mongodb') { diff --git a/bootstrap/helpers/databases.php b/bootstrap/helpers/databases.php index b8dcc1f3c..950eb67b6 100644 --- a/bootstrap/helpers/databases.php +++ b/bootstrap/helpers/databases.php @@ -19,7 +19,7 @@ function generate_database_name(string $type): string return $type.'-database-'.$cuid; } -function create_standalone_postgresql($environmentId, $destinationUuid, ?array $otherData = null): StandalonePostgresql +function create_standalone_postgresql($environmentId, $destinationUuid, ?array $otherData = null, string $databaseImage = 'postgres:16-alpine'): StandalonePostgresql { $destination = StandaloneDocker::where('uuid', $destinationUuid)->first(); if (! $destination) { @@ -27,6 +27,7 @@ function create_standalone_postgresql($environmentId, $destinationUuid, ?array $ } $database = new StandalonePostgresql; $database->name = generate_database_name('postgresql'); + $database->image = $databaseImage; $database->postgres_password = \Illuminate\Support\Str::password(length: 64, symbols: false); $database->environment_id = $environmentId; $database->destination_id = $destination->id; diff --git a/resources/views/livewire/project/new/select.blade.php b/resources/views/livewire/project/new/select.blade.php index 758df6508..d5dea76e2 100644 --- a/resources/views/livewire/project/new/select.blade.php +++ b/resources/views/livewire/project/new/select.blade.php @@ -617,6 +617,85 @@ @endif @endif + @if ($current_step === 'select-postgresql-type') +