2023-08-07 22:14:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
|
|
|
class StandalonePostgresql extends BaseModel
|
|
|
|
{
|
|
|
|
use HasFactory;
|
2023-08-08 11:51:36 +02:00
|
|
|
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
|
|
'postgres_password' => 'encrypted',
|
|
|
|
];
|
|
|
|
|
2023-08-07 22:14:21 +02:00
|
|
|
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
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
|
|
|
public function type()
|
|
|
|
{
|
2023-08-07 22:14:21 +02:00
|
|
|
return 'standalone-postgresql';
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-08-07 22:14:21 +02:00
|
|
|
public function environment()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Environment::class);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-08-07 22:14:21 +02:00
|
|
|
public function destination()
|
|
|
|
{
|
|
|
|
return $this->morphTo();
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
|
|
|
public function environment_variables(): HasMany
|
2023-08-07 22:14:21 +02:00
|
|
|
{
|
|
|
|
return $this->hasMany(EnvironmentVariable::class);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-08-07 22:27:20 +02:00
|
|
|
public function runtime_environment_variables(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(EnvironmentVariable::class);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-08-07 22:14:21 +02:00
|
|
|
public function persistentStorages()
|
|
|
|
{
|
|
|
|
return $this->morphMany(LocalPersistentVolume::class, 'resource');
|
|
|
|
}
|
|
|
|
}
|