diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index 96b843876..12d540aab 100644 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -115,16 +115,19 @@ private function cleanup_stucked_resources() $applications = Application::all(); foreach ($applications as $application) { if (!data_get($application, 'environment')) { - echo 'Application without environment: ' . $application->name . ' deleting\n'; + echo 'Application without environment: ' . $application->name . ' soft deleting\n'; $application->delete(); + continue; } if (!$application->destination()) { - echo 'Application without destination: ' . $application->name . ' deleting\n'; + echo 'Application without destination: ' . $application->name . ' soft deleting\n'; $application->delete(); + continue; } if (!data_get($application, 'destination.server')) { - echo 'Application without server: ' . $application->name . ' deleting\n'; + echo 'Application without server: ' . $application->name . ' soft deleting\n'; $application->delete(); + continue; } } } catch (\Throwable $e) { @@ -134,16 +137,19 @@ private function cleanup_stucked_resources() $postgresqls = StandalonePostgresql::all(); foreach ($postgresqls as $postgresql) { if (!data_get($postgresql, 'environment')) { - echo 'Postgresql without environment: ' . $postgresql->name . ' deleting\n'; + echo 'Postgresql without environment: ' . $postgresql->name . ' soft deleting\n'; $postgresql->delete(); + continue; } if (!$postgresql->destination()) { - echo 'Postgresql without destination: ' . $postgresql->name . ' deleting\n'; + echo 'Postgresql without destination: ' . $postgresql->name . ' soft deleting\n'; $postgresql->delete(); + continue; } if (!data_get($postgresql, 'destination.server')) { - echo 'Postgresql without server: ' . $postgresql->name . ' deleting\n'; + echo 'Postgresql without server: ' . $postgresql->name . ' soft deleting\n'; $postgresql->delete(); + continue; } } } catch (\Throwable $e) { @@ -153,16 +159,19 @@ private function cleanup_stucked_resources() $redis = StandaloneRedis::all(); foreach ($redis as $redis) { if (!data_get($redis, 'environment')) { - echo 'Redis without environment: ' . $redis->name . ' deleting\n'; + echo 'Redis without environment: ' . $redis->name . ' soft deleting\n'; $redis->delete(); + continue; } if (!$redis->destination()) { - echo 'Redis without destination: ' . $redis->name . ' deleting\n'; + echo 'Redis without destination: ' . $redis->name . ' soft deleting\n'; $redis->delete(); + continue; } if (!data_get($redis, 'destination.server')) { - echo 'Redis without server: ' . $redis->name . ' deleting\n'; + echo 'Redis without server: ' . $redis->name . ' soft deleting\n'; $redis->delete(); + continue; } } } catch (\Throwable $e) { @@ -173,16 +182,19 @@ private function cleanup_stucked_resources() $mongodbs = StandaloneMongodb::all(); foreach ($mongodbs as $mongodb) { if (!data_get($mongodb, 'environment')) { - echo 'Mongodb without environment: ' . $mongodb->name . ' deleting\n'; + echo 'Mongodb without environment: ' . $mongodb->name . ' soft deleting\n'; $mongodb->delete(); + continue; } if (!$mongodb->destination()) { - echo 'Mongodb without destination: ' . $mongodb->name . ' deleting\n'; + echo 'Mongodb without destination: ' . $mongodb->name . ' soft deleting\n'; $mongodb->delete(); + continue; } if (!data_get($mongodb, 'destination.server')) { - echo 'Mongodb without server: ' . $mongodb->name . ' deleting\n'; + echo 'Mongodb without server: ' . $mongodb->name . ' soft deleting\n'; $mongodb->delete(); + continue; } } } catch (\Throwable $e) { @@ -193,16 +205,19 @@ private function cleanup_stucked_resources() $mysqls = StandaloneMysql::all(); foreach ($mysqls as $mysql) { if (!data_get($mysql, 'environment')) { - echo 'Mysql without environment: ' . $mysql->name . ' deleting\n'; + echo 'Mysql without environment: ' . $mysql->name . ' soft deleting\n'; $mysql->delete(); + continue; } if (!$mysql->destination()) { - echo 'Mysql without destination: ' . $mysql->name . ' deleting\n'; + echo 'Mysql without destination: ' . $mysql->name . ' soft deleting\n'; $mysql->delete(); + continue; } if (!data_get($mysql, 'destination.server')) { - echo 'Mysql without server: ' . $mysql->name . ' deleting\n'; + echo 'Mysql without server: ' . $mysql->name . ' soft deleting\n'; $mysql->delete(); + continue; } } } catch (\Throwable $e) { @@ -213,16 +228,19 @@ private function cleanup_stucked_resources() $mariadbs = StandaloneMariadb::all(); foreach ($mariadbs as $mariadb) { if (!data_get($mariadb, 'environment')) { - echo 'Mariadb without environment: ' . $mariadb->name . ' deleting\n'; + echo 'Mariadb without environment: ' . $mariadb->name . ' soft deleting\n'; $mariadb->delete(); + continue; } if (!$mariadb->destination()) { - echo 'Mariadb without destination: ' . $mariadb->name . ' deleting\n'; + echo 'Mariadb without destination: ' . $mariadb->name . ' soft deleting\n'; $mariadb->delete(); + continue; } if (!data_get($mariadb, 'destination.server')) { - echo 'Mariadb without server: ' . $mariadb->name . ' deleting\n'; + echo 'Mariadb without server: ' . $mariadb->name . ' soft deleting\n'; $mariadb->delete(); + continue; } } } catch (\Throwable $e) { @@ -233,16 +251,19 @@ private function cleanup_stucked_resources() $services = Service::all(); foreach ($services as $service) { if (!data_get($service, 'environment')) { - echo 'Service without environment: ' . $service->name . ' deleting\n'; + echo 'Service without environment: ' . $service->name . ' soft deleting\n'; $service->delete(); + continue; } if (!$service->destination()) { - echo 'Service without destination: ' . $service->name . ' deleting\n'; + echo 'Service without destination: ' . $service->name . ' soft deleting\n'; $service->delete(); + continue; } if (!data_get($service, 'server')) { - echo 'Service without server: ' . $service->name . ' deleting\n'; + echo 'Service without server: ' . $service->name . ' soft deleting\n'; $service->delete(); + continue; } } } catch (\Throwable $e) { @@ -252,8 +273,9 @@ private function cleanup_stucked_resources() $serviceApplications = ServiceApplication::all(); foreach ($serviceApplications as $service) { if (!data_get($service, 'service')) { - echo 'ServiceApplication without service: ' . $service->name . ' deleting\n'; + echo 'ServiceApplication without service: ' . $service->name . ' soft deleting\n'; $service->delete(); + continue; } } } catch (\Throwable $e) { @@ -263,8 +285,9 @@ private function cleanup_stucked_resources() $serviceDatabases = ServiceDatabase::all(); foreach ($serviceDatabases as $service) { if (!data_get($service, 'service')) { - echo 'ServiceDatabase without service: ' . $service->name . ' deleting\n'; + echo 'ServiceDatabase without service: ' . $service->name . ' soft deleting\n'; $service->delete(); + continue; } } } catch (\Throwable $e) { diff --git a/app/Models/Application.php b/app/Models/Application.php index d56be8f0a..e58d4a028 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection; use Spatie\Activitylog\Models\Activity; use Illuminate\Support\Str; @@ -13,6 +14,7 @@ class Application extends BaseModel { + use SoftDeletes; protected $guarded = []; protected static function booted() diff --git a/app/Models/ServiceApplication.php b/app/Models/ServiceApplication.php index b8e3f1a41..510395266 100644 --- a/app/Models/ServiceApplication.php +++ b/app/Models/ServiceApplication.php @@ -4,11 +4,12 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\Cache; class ServiceApplication extends BaseModel { - use HasFactory; + use HasFactory, SoftDeletes; protected $guarded = []; protected static function booted() diff --git a/app/Models/ServiceDatabase.php b/app/Models/ServiceDatabase.php index 79c1dd176..0bde42c20 100644 --- a/app/Models/ServiceDatabase.php +++ b/app/Models/ServiceDatabase.php @@ -3,10 +3,11 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\SoftDeletes; class ServiceDatabase extends BaseModel { - use HasFactory; + use HasFactory, SoftDeletes; protected $guarded = []; protected static function booted() diff --git a/app/Models/StandaloneMariadb.php b/app/Models/StandaloneMariadb.php index 8893632d3..33c00260e 100644 --- a/app/Models/StandaloneMariadb.php +++ b/app/Models/StandaloneMariadb.php @@ -6,10 +6,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\SoftDeletes; class StandaloneMariadb extends BaseModel { - use HasFactory; + use HasFactory,SoftDeletes; protected $guarded = []; protected $casts = [ diff --git a/app/Models/StandaloneMongodb.php b/app/Models/StandaloneMongodb.php index c041c9407..d08c04adb 100644 --- a/app/Models/StandaloneMongodb.php +++ b/app/Models/StandaloneMongodb.php @@ -5,10 +5,11 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\SoftDeletes; class StandaloneMongodb extends BaseModel { - use HasFactory; + use HasFactory, SoftDeletes; protected $guarded = []; protected static function booted() diff --git a/app/Models/StandaloneMysql.php b/app/Models/StandaloneMysql.php index a4691b9b2..02f8f82c4 100644 --- a/app/Models/StandaloneMysql.php +++ b/app/Models/StandaloneMysql.php @@ -5,10 +5,11 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\SoftDeletes; class StandaloneMysql extends BaseModel { - use HasFactory; + use HasFactory, SoftDeletes; protected $guarded = []; protected $casts = [ diff --git a/app/Models/StandalonePostgresql.php b/app/Models/StandalonePostgresql.php index e0db00d76..df9d28460 100644 --- a/app/Models/StandalonePostgresql.php +++ b/app/Models/StandalonePostgresql.php @@ -5,10 +5,11 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\SoftDeletes; class StandalonePostgresql extends BaseModel { - use HasFactory; + use HasFactory, SoftDeletes; protected $guarded = []; protected $casts = [ diff --git a/app/Models/StandaloneRedis.php b/app/Models/StandaloneRedis.php index 95add8315..7ccde7f68 100644 --- a/app/Models/StandaloneRedis.php +++ b/app/Models/StandaloneRedis.php @@ -5,10 +5,11 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\SoftDeletes; class StandaloneRedis extends BaseModel { - use HasFactory; + use HasFactory, SoftDeletes; protected $guarded = []; protected static function booted() diff --git a/database/migrations/2023_12_13_110214_add_soft_deletes.php b/database/migrations/2023_12_13_110214_add_soft_deletes.php new file mode 100644 index 000000000..ab7b562b4 --- /dev/null +++ b/database/migrations/2023_12_13_110214_add_soft_deletes.php @@ -0,0 +1,71 @@ +softDeletes(); + }); + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->softDeletes(); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->softDeletes(); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->softDeletes(); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->softDeletes(); + }); + Schema::table('standalone_mariadbs', function (Blueprint $table) { + $table->softDeletes(); + }); + Schema::table('service_applications', function (Blueprint $table) { + $table->softDeletes(); + }); + Schema::table('service_databases', function (Blueprint $table) { + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('applications', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + Schema::table('standalone_mariadbs', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + Schema::table('service_applications', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + Schema::table('service_databases', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + + } +};