diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index ec4d75484..b784c4e67 100644 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -7,6 +7,7 @@ use App\Jobs\CleanupHelperContainersJob; use App\Models\Application; use App\Models\ApplicationDeploymentQueue; use App\Models\InstanceSettings; +use App\Models\ScheduledDatabaseBackup; use App\Models\Server; use App\Models\Service; use App\Models\ServiceApplication; @@ -31,6 +32,9 @@ class Init extends Command if ($cleanup) { echo "Running cleanup\n"; $this->cleanup_stucked_resources(); + // Required for falsely deleted coolify db + $this->restore_coolify_db_backup(); + // $this->cleanup_ssh(); } $this->cleanup_in_progress_application_deployments(); @@ -51,6 +55,30 @@ class Init extends Command } } } + private function restore_coolify_db_backup() { + try { + $database = StandalonePostgresql::withTrashed()->find(0); + if ($database && $database->trashed()) { + echo "Restoring coolify db backup\n"; + $database->restore(); + $scheduledBackup = ScheduledDatabaseBackup::find(0); + if (!$scheduledBackup) { + ScheduledDatabaseBackup::create([ + 'id' => 0, + 'enabled' => true, + 'save_s3' => false, + 'frequency' => '0 0 * * *', + 'database_id' => $database->id, + 'database_type' => 'App\Models\StandalonePostgresql', + 'team_id' => 0, + ]); + } + + } + } catch(\Throwable $e) { + echo "Error in restoring coolify db backup: {$e->getMessage()}\n"; + } + } private function cleanup_stucked_helper_containers() { $servers = Server::all(); @@ -134,7 +162,7 @@ class Init extends Command echo "Error in application: {$e->getMessage()}\n"; } try { - $postgresqls = StandalonePostgresql::all(); + $postgresqls = StandalonePostgresql::all()->where('id', '!=', 0); foreach ($postgresqls as $postgresql) { if (!data_get($postgresql, 'environment')) { echo 'Postgresql without environment: ' . $postgresql->name . ' soft deleting\n'; diff --git a/config/sentry.php b/config/sentry.php index 7385f166d..ff9cafff0 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.173', + 'release' => '4.0.0-beta.174', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 29b58ddbe..24294cc83 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@