Skip to content

Commit

Permalink
Ensure database name uses underscores instead of hyphens
Browse files Browse the repository at this point in the history
  • Loading branch information
owenconti committed Jan 12, 2024
1 parent 2b24053 commit 977a4b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/Commands/DeleteSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Commands;

use App\Traits\UseForgeSdk;
use Illuminate\Support\Str;
use LaravelZero\Framework\Commands\Command;
use Laravel\Forge\Exceptions\ValidationException;
use Laravel\Forge\Resources\Database;
Expand All @@ -20,11 +21,13 @@ class DeleteSite extends Command
protected $description = 'Deletes the site on the server, including the database.';

protected string $domain;
protected string $databaseName;

public function handle(): void
{
$this->buildForge();
$this->domain = $this->argument('subdomain') . '.' . $this->argument('root-domain');
$this->databaseName = Str::replace($this->argument('subdomain'), '-', '_');

try {
$this->deleteSite();
Expand All @@ -34,13 +37,13 @@ public function handle(): void
}
}

protected function getDatabase(): Database
protected function getDatabase(): ?Database
{
$this->output->info('Checking for database...');

$databases = collect($this->forge->databases($this->forgeServerId));

return $databases->first(fn (Database $database) => $database->name === $this->argument('subdomain'));
return $databases->first(fn (Database $database) => $database->name === $this->databaseName);
}

protected function deleteSite(): void
Expand Down
5 changes: 4 additions & 1 deletion app/Commands/DeploySite.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Commands;

use Illuminate\Support\Str;
use LaravelZero\Framework\Commands\Command;
use Laravel\Forge\Exceptions\ValidationException;
use Laravel\Forge\Forge;
Expand All @@ -24,6 +25,7 @@ class DeploySite extends Command
protected $description = 'Deploys the given branch to the server.';

protected string $domain;
protected string $databaseName;
protected Forge $forge;
protected string $forgeApiToken;
protected string $forgeServerId;
Expand All @@ -32,6 +34,7 @@ public function handle(): void
{
$this->buildForge();
$this->domain = $this->argument('subdomain') . '.' . $this->argument('root-domain');
$this->databaseName = Str::replace($this->argument('subdomain'), '-', '_');

try {
$site = $this->getSite();
Expand Down Expand Up @@ -60,7 +63,7 @@ protected function createSite(): Site

$site = $this->forge->createSite($this->forgeServerId, [
'domain' => $this->domain,
'database' => $this->argument('subdomain'),
'database' => $this->databaseName,
'project_type' => 'php',
'php_version' => $this->argument('php-version'),
'aliases' => [],
Expand Down
Binary file modified builds/forge-review-apps
Binary file not shown.

0 comments on commit 977a4b2

Please sign in to comment.