lots of updates + refactoring
This commit is contained in:
@@ -43,7 +43,9 @@ class Application extends BaseModel
|
||||
'publish_directory',
|
||||
'private_key_id'
|
||||
];
|
||||
|
||||
public function type() {
|
||||
return 'application';
|
||||
}
|
||||
public function publishDirectory(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
@@ -206,4 +208,4 @@ class Application extends BaseModel
|
||||
}
|
||||
throw new \Exception('No deployment type found');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ class Environment extends Model
|
||||
}
|
||||
public function postgresqls()
|
||||
{
|
||||
return $this->hasMany(StandalonePostgres::class);
|
||||
return $this->hasMany(StandalonePostgresql::class);
|
||||
}
|
||||
public function services()
|
||||
{
|
||||
return $this->hasMany(Service::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,26 +9,27 @@ use Illuminate\Support\Str;
|
||||
|
||||
class EnvironmentVariable extends Model
|
||||
{
|
||||
protected static function booted()
|
||||
{
|
||||
static::created(function ($environment_variable) {
|
||||
if (!$environment_variable->is_preview) {
|
||||
ModelsEnvironmentVariable::create([
|
||||
'key' => $environment_variable->key,
|
||||
'value' => $environment_variable->value,
|
||||
'is_build_time' => $environment_variable->is_build_time,
|
||||
'application_id' => $environment_variable->application_id,
|
||||
'is_preview' => true,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
protected $fillable = ['key', 'value', 'is_build_time', 'application_id', 'is_preview'];
|
||||
protected $guarded = [];
|
||||
protected $casts = [
|
||||
"key" => 'string',
|
||||
'value' => 'encrypted',
|
||||
'is_build_time' => 'boolean',
|
||||
];
|
||||
protected static function booted()
|
||||
{
|
||||
static::created(function ($environment_variable) {
|
||||
if ($environment_variable->application_id && !$environment_variable->is_preview) {
|
||||
ModelsEnvironmentVariable::create([
|
||||
'key' => $environment_variable->key,
|
||||
'value' => $environment_variable->value,
|
||||
'is_build_time' => $environment_variable->is_build_time,
|
||||
'application_id' => $environment_variable->application_id,
|
||||
'is_preview' => true,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function get_environment_variables(string $environment_variable): string|null
|
||||
{
|
||||
// $team_id = session('currentTeam')->id;
|
||||
|
||||
@@ -8,18 +8,15 @@ use Illuminate\Support\Str;
|
||||
|
||||
class LocalPersistentVolume extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'mount_path',
|
||||
'host_path',
|
||||
'container_id',
|
||||
'resource_id',
|
||||
'resource_type',
|
||||
];
|
||||
protected $guarded = [];
|
||||
public function application()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
public function standalone_postgresql()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
protected function name(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
|
||||
@@ -48,6 +48,6 @@ class Project extends BaseModel
|
||||
}
|
||||
public function postgresqls()
|
||||
{
|
||||
return $this->hasManyThrough(StandalonePostgres::class, Environment::class);
|
||||
return $this->hasManyThrough(StandalonePostgresql::class, Environment::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class StandaloneDocker extends BaseModel
|
||||
}
|
||||
public function postgresqls()
|
||||
{
|
||||
return $this->morphMany(StandalonePostgres::class, 'destination');
|
||||
return $this->morphMany(StandalonePostgresql::class, 'destination');
|
||||
}
|
||||
public function server()
|
||||
{
|
||||
@@ -25,4 +25,4 @@ class StandaloneDocker extends BaseModel
|
||||
{
|
||||
return $this->applications->count() > 0 || $this->databases->count() > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class StandalonePostgres extends BaseModel
|
||||
{
|
||||
use HasFactory;
|
||||
protected $guarded = [];
|
||||
protected $casts = [
|
||||
'postgres_password' => 'encrypted',
|
||||
];
|
||||
public function type() {
|
||||
return 'postgresql';
|
||||
}
|
||||
public function environment()
|
||||
{
|
||||
return $this->belongsTo(Environment::class);
|
||||
}
|
||||
public function destination()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
||||
50
app/Models/StandalonePostgresql.php
Normal file
50
app/Models/StandalonePostgresql.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use App\Models\EnvironmentVariable;
|
||||
use App\Models\LocalPersistentVolume;
|
||||
|
||||
class StandalonePostgresql extends BaseModel
|
||||
{
|
||||
use HasFactory;
|
||||
protected static function booted()
|
||||
{
|
||||
static::created(function ($database) {
|
||||
LocalPersistentVolume::create([
|
||||
'name' => 'postgres-data-' . $database->uuid,
|
||||
'mount_path' => '/var/lib/postgresql/data',
|
||||
'host_path' => null,
|
||||
'resource_id' => $database->id,
|
||||
'resource_type' => $database->getMorphClass(),
|
||||
'is_readonly' => true
|
||||
]);
|
||||
});
|
||||
}
|
||||
protected $guarded = [];
|
||||
protected $casts = [
|
||||
'postgres_password' => 'encrypted',
|
||||
];
|
||||
public function type() {
|
||||
return 'standalone-postgresql';
|
||||
}
|
||||
public function environment()
|
||||
{
|
||||
return $this->belongsTo(Environment::class);
|
||||
}
|
||||
public function destination()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
public function environment_variables(): HasMany
|
||||
{
|
||||
return $this->hasMany(EnvironmentVariable::class);
|
||||
}
|
||||
|
||||
public function persistentStorages()
|
||||
{
|
||||
return $this->morphMany(LocalPersistentVolume::class, 'resource');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user