Refactor to remove slices and environments, replace with instances.
This commit is contained in:
@@ -6,6 +6,8 @@ use App\Enums\RepositoryType;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
class Application extends Model
|
||||
{
|
||||
@@ -23,8 +25,18 @@ class Application extends Model
|
||||
return $this->belongsTo(Organisation::class);
|
||||
}
|
||||
|
||||
public function environments(): HasMany
|
||||
public function instances(): HasMany
|
||||
{
|
||||
return $this->hasMany(Environment::class);
|
||||
return $this->hasMany(Instance::class);
|
||||
}
|
||||
|
||||
public function servers(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Server::class, Instance::class);
|
||||
}
|
||||
|
||||
public function deployments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Deployment::class, 'target');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
|
||||
class Environment extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function application(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Application::class);
|
||||
}
|
||||
|
||||
public function slices(): HasMany
|
||||
{
|
||||
return $this->hasMany(Slice::class);
|
||||
}
|
||||
|
||||
public function services(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Service::class, Slice::class);
|
||||
}
|
||||
}
|
||||
34
app/Models/Instance.php
Normal file
34
app/Models/Instance.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
class Instance extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'config' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function application(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Application::class);
|
||||
}
|
||||
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
public function deployments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Deployment::class, 'target');
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,16 @@ class Server extends Model
|
||||
return $this->hasMany(Service::class);
|
||||
}
|
||||
|
||||
public function instances(): HasMany
|
||||
{
|
||||
return $this->hasMany(Instance::class);
|
||||
}
|
||||
|
||||
public function applications(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Application::class, Instance::class);
|
||||
}
|
||||
|
||||
public function firewallRules(): HasMany
|
||||
{
|
||||
return $this->hasMany(FirewallRule::class);
|
||||
@@ -64,14 +74,14 @@ class Server extends Model
|
||||
)->where('target_type', (new Service)->getMorphClass());
|
||||
}
|
||||
|
||||
public function environmentDeployments(): HasManyThrough
|
||||
public function applicationDeployments(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
Deployment::class,
|
||||
Environment::class,
|
||||
Application::class,
|
||||
'server_id',
|
||||
'target_id',
|
||||
)->where('target_type', (new Environment)->getMorphClass());
|
||||
)->where('target_type', (new Application)->getMorphClass());
|
||||
}
|
||||
|
||||
public function sshClient(string $user = 'root'): Ssh
|
||||
|
||||
@@ -10,7 +10,6 @@ use App\Enums\ServiceType;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
class Service extends Model
|
||||
@@ -41,11 +40,6 @@ class Service extends Model
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
public function slices(): HasMany
|
||||
{
|
||||
return $this->hasMany(Slice::class);
|
||||
}
|
||||
|
||||
public function deployments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Deployment::class, 'target');
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Slice extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function service(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user