2023-03-27 08:44:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2023-04-25 12:43:35 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Environment extends Model
|
2023-03-27 08:44:31 +00:00
|
|
|
{
|
2023-10-24 08:43:34 +00:00
|
|
|
protected $guarded = [];
|
2024-05-21 12:29:06 +00:00
|
|
|
|
|
|
|
protected static function booted()
|
|
|
|
{
|
|
|
|
static::deleting(function ($environment) {
|
|
|
|
$shared_variables = $environment->environment_variables();
|
|
|
|
foreach ($shared_variables as $shared_variable) {
|
2024-06-10 20:43:34 +00:00
|
|
|
ray('Deleting environment shared variable: '.$shared_variable->name);
|
2024-05-21 12:29:06 +00:00
|
|
|
$shared_variable->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-10-24 08:11:21 +00:00
|
|
|
public function isEmpty()
|
2023-04-25 12:43:35 +00:00
|
|
|
{
|
2023-10-19 11:32:03 +00:00
|
|
|
return $this->applications()->count() == 0 &&
|
|
|
|
$this->redis()->count() == 0 &&
|
|
|
|
$this->postgresqls()->count() == 0 &&
|
2024-02-05 19:15:02 +00:00
|
|
|
$this->mysqls()->count() == 0 &&
|
2024-06-28 09:00:02 +00:00
|
|
|
$this->keydbs()->count() == 0 &&
|
|
|
|
$this->dragonflies()->count() == 0 &&
|
|
|
|
$this->clickhouses()->count() == 0 &&
|
2024-02-05 19:15:02 +00:00
|
|
|
$this->mariadbs()->count() == 0 &&
|
2023-10-19 11:32:03 +00:00
|
|
|
$this->mongodbs()->count() == 0 &&
|
|
|
|
$this->services()->count() == 0;
|
2023-08-07 16:46:40 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
public function environment_variables()
|
|
|
|
{
|
2024-01-23 16:13:23 +00:00
|
|
|
return $this->hasMany(SharedEnvironmentVariable::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-03-27 08:44:31 +00:00
|
|
|
public function applications()
|
|
|
|
{
|
2023-03-27 16:14:33 +00:00
|
|
|
return $this->hasMany(Application::class);
|
2023-03-27 08:44:31 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-08-07 16:46:40 +00:00
|
|
|
public function postgresqls()
|
2023-03-27 08:44:31 +00:00
|
|
|
{
|
2023-08-07 20:14:21 +00:00
|
|
|
return $this->hasMany(StandalonePostgresql::class);
|
2023-03-27 08:44:31 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-10-12 15:18:33 +00:00
|
|
|
public function redis()
|
|
|
|
{
|
|
|
|
return $this->hasMany(StandaloneRedis::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-10-19 11:32:03 +00:00
|
|
|
public function mongodbs()
|
|
|
|
{
|
|
|
|
return $this->hasMany(StandaloneMongodb::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-10-24 12:31:28 +00:00
|
|
|
public function mysqls()
|
|
|
|
{
|
|
|
|
return $this->hasMany(StandaloneMysql::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-10-24 12:31:28 +00:00
|
|
|
public function mariadbs()
|
|
|
|
{
|
|
|
|
return $this->hasMany(StandaloneMariadb::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-10 13:00:46 +00:00
|
|
|
public function keydbs()
|
|
|
|
{
|
|
|
|
return $this->hasMany(StandaloneKeydb::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-10 13:00:46 +00:00
|
|
|
public function dragonflies()
|
|
|
|
{
|
|
|
|
return $this->hasMany(StandaloneDragonfly::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-10 13:00:46 +00:00
|
|
|
public function clickhouses()
|
|
|
|
{
|
|
|
|
return $this->hasMany(StandaloneClickhouse::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-08-08 09:51:36 +00:00
|
|
|
public function databases()
|
|
|
|
{
|
2023-10-12 15:18:33 +00:00
|
|
|
$postgresqls = $this->postgresqls;
|
|
|
|
$redis = $this->redis;
|
2023-10-19 11:32:03 +00:00
|
|
|
$mongodbs = $this->mongodbs;
|
2023-10-24 12:31:28 +00:00
|
|
|
$mysqls = $this->mysqls;
|
|
|
|
$mariadbs = $this->mariadbs;
|
2024-04-10 13:00:46 +00:00
|
|
|
$keydbs = $this->keydbs;
|
|
|
|
$dragonflies = $this->dragonflies;
|
|
|
|
$clickhouses = $this->clickhouses;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-10 13:00:46 +00:00
|
|
|
return $postgresqls->concat($redis)->concat($mongodbs)->concat($mysqls)->concat($mariadbs)->concat($keydbs)->concat($dragonflies)->concat($clickhouses);
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function project()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Project::class);
|
|
|
|
}
|
|
|
|
|
2023-03-28 06:28:03 +00:00
|
|
|
public function services()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Service::class);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
protected function name(): Attribute
|
|
|
|
{
|
|
|
|
return Attribute::make(
|
2024-06-23 15:47:58 +00:00
|
|
|
set: fn (string $value) => str($value)->lower()->trim()->replace('/', '-')->toString(),
|
2023-08-08 09:51:36 +00:00
|
|
|
);
|
|
|
|
}
|
2023-08-07 20:14:21 +00:00
|
|
|
}
|