Skip to content

Revert "Fix #134: Add option to force delete and recreate existing database" #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ hashFiles('**/composer.lock') }}
Expand Down
93 changes: 0 additions & 93 deletions app/Services/Forge/Actions/RecreateDatabase.php

This file was deleted.

6 changes: 0 additions & 6 deletions app/Services/Forge/ForgeSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ class ForgeSetting
*/
public bool $dbCreationRequired;

/**
* Flag indicating if Harbor should remove the existing old database.
*/
public bool $forceDeleteOldDatabase;

/**
* The name of the database to be created
*/
Expand Down Expand Up @@ -263,7 +258,6 @@ protected function validate(array $configurations): \Illuminate\Validation\Valid
'site_isolation_username' => ['nullable', 'string'],
'job_scheduler_required' => ['boolean'],
'db_creation_required' => ['boolean'],
'force_delete_old_database' => ['boolean'],
'db_name' => ['nullable', 'string'],
'auto_source_required' => ['boolean'],
'ssl_required' => ['boolean'],
Expand Down
35 changes: 23 additions & 12 deletions app/Services/Forge/Pipeline/CreateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace App\Services\Forge\Pipeline;

use App\Services\Forge\Actions\RecreateDatabase;
use App\Services\Forge\ForgeService;
use App\Traits\Outputifier;
use Closure;
Expand All @@ -22,14 +21,7 @@
class CreateDatabase
{
use Outputifier;

private RecreateDatabase $recreateDatabase;

public function __construct(RecreateDatabase $recreateDatabase = null)
{
$this->recreateDatabase = $recreateDatabase ?? new RecreateDatabase();
}

public function __invoke(ForgeService $service, Closure $next)
{
if (! $service->setting->dbCreationRequired || ! $service->siteNewlyMade) {
Expand All @@ -38,9 +30,12 @@ public function __invoke(ForgeService $service, Closure $next)

$dbName = $service->getFormattedDatabaseName();
$dbPassword = Str::random(16);

// Handle DB recreation and creation in one call
$this->recreateDatabase->handle($service, $dbName, $dbPassword);

if (! $this->databaseExists($service, $dbName)) {
$this->information('Creating database.');

$this->createDatabase($service, $dbName, $dbPassword);
}

$service->setDatabase([
'DB_DATABASE' => $dbName,
Expand All @@ -51,7 +46,23 @@ public function __invoke(ForgeService $service, Closure $next)
return $next($service);
}

protected function databaseExists(ForgeService $service, string $dbName): bool
{
foreach ($service->forge->databases($service->server->id) as $database) {
if ($database->name === $dbName) {
return true;
}
}

return false;
}


protected function createDatabase(ForgeService $service, string $dbName, string $dbPassword): void
{
$service->forge->createDatabase($service->server->id, [
'name' => $dbName,
'user' => $dbName,
'password' => $dbPassword,
]);
}
}
3 changes: 0 additions & 3 deletions config/forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
// Flag indicating if a database should be created (default: false).
'db_creation_required' => env('FORGE_DB_CREATION_REQUIRED', false),

// Flag indicating if Harbor should remove the existing old database (default: false).
'force_delete_old_database' => env('FORCE_DELETE_OLD_DATABASE', false),

// Flag to enable Quick Deploy (default: true).
'quick_deploy' => env('FORGE_QUICK_DEPLOY', false),

Expand Down
152 changes: 0 additions & 152 deletions tests/Unit/Services/Forge/Actions/RecreateDatabaseTest.php

This file was deleted.

Loading