feat: init postgresql database
This commit is contained in:
@@ -17,6 +17,12 @@ class Environment extends Model
|
||||
set: fn (string $value) => strtolower($value),
|
||||
);
|
||||
}
|
||||
public function can_delete_environment() {
|
||||
return $this->applications()->count() == 0 && $this->postgresqls()->count() == 0;
|
||||
}
|
||||
public function databases() {
|
||||
return $this->postgresqls();
|
||||
}
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
@@ -25,12 +31,12 @@ class Environment extends Model
|
||||
{
|
||||
return $this->hasMany(Application::class);
|
||||
}
|
||||
public function databases()
|
||||
public function postgresqls()
|
||||
{
|
||||
return $this->hasMany(Database::class);
|
||||
return $this->hasMany(Postgresql::class);
|
||||
}
|
||||
public function services()
|
||||
{
|
||||
return $this->hasMany(Service::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
app/Models/Postgresql.php
Normal file
25
app/Models/Postgresql.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Postgresql 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();
|
||||
}
|
||||
}
|
||||
@@ -46,4 +46,8 @@ class Project extends BaseModel
|
||||
{
|
||||
return $this->hasManyThrough(Application::class, Environment::class);
|
||||
}
|
||||
}
|
||||
public function postgresqls()
|
||||
{
|
||||
return $this->hasManyThrough(Postgresql::class, Environment::class);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,10 @@ class S3Storage extends BaseModel
|
||||
{
|
||||
use HasFactory;
|
||||
protected $guarded = [];
|
||||
protected $casts = [
|
||||
'key' => 'encrypted',
|
||||
'secret' => 'encrypted',
|
||||
];
|
||||
|
||||
static public function ownedByCurrentTeam(array $select = ['*'])
|
||||
{
|
||||
|
||||
@@ -13,9 +13,9 @@ class StandaloneDocker extends BaseModel
|
||||
{
|
||||
return $this->morphMany(Application::class, 'destination');
|
||||
}
|
||||
public function databases()
|
||||
public function postgresqls()
|
||||
{
|
||||
return $this->morphMany(Database::class, 'destination');
|
||||
return $this->morphMany(Postgresql::class, 'destination');
|
||||
}
|
||||
public function server()
|
||||
{
|
||||
@@ -25,4 +25,4 @@ class StandaloneDocker extends BaseModel
|
||||
{
|
||||
return $this->applications->count() > 0 || $this->databases->count() > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user