refactor: improve migration command and enhance application model with global scope and status checks
This commit is contained in:
@@ -14,7 +14,7 @@ class Migration extends Command
|
|||||||
{
|
{
|
||||||
if (config('constants.migration.is_migration_enabled')) {
|
if (config('constants.migration.is_migration_enabled')) {
|
||||||
$this->info('Migration is enabled on this server.');
|
$this->info('Migration is enabled on this server.');
|
||||||
$this->call('migrate --force --isolated');
|
$this->call('migrate', ['--force' => true, '--isolated' => true]);
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
$this->info('Migration is disabled on this server.');
|
$this->info('Migration is disabled on this server.');
|
||||||
|
|||||||
@@ -115,6 +115,12 @@ class Application extends BaseModel
|
|||||||
|
|
||||||
protected static function booted()
|
protected static function booted()
|
||||||
{
|
{
|
||||||
|
static::addGlobalScope('withRelations', function ($builder) {
|
||||||
|
$builder->withCount([
|
||||||
|
'additional_servers',
|
||||||
|
'additional_networks',
|
||||||
|
]);
|
||||||
|
});
|
||||||
static::saving(function ($application) {
|
static::saving(function ($application) {
|
||||||
$payload = [];
|
$payload = [];
|
||||||
if ($application->isDirty('fqdn')) {
|
if ($application->isDirty('fqdn')) {
|
||||||
@@ -551,11 +557,13 @@ class Application extends BaseModel
|
|||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: function () {
|
get: function () {
|
||||||
if ($this->additional_servers->count() === 0) {
|
if (! $this->relationLoaded('additional_servers') || $this->additional_servers->count() === 0) {
|
||||||
return $this->destination->server->isFunctional();
|
return $this->destination?->server?->isFunctional() ?? false;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
$additional_servers_status = $this->additional_servers->pluck('pivot.status');
|
$additional_servers_status = $this->additional_servers->pluck('pivot.status');
|
||||||
$main_server_status = $this->destination->server->isFunctional();
|
$main_server_status = $this->destination?->server?->isFunctional() ?? false;
|
||||||
|
|
||||||
foreach ($additional_servers_status as $status) {
|
foreach ($additional_servers_status as $status) {
|
||||||
$server_status = str($status)->before(':')->value();
|
$server_status = str($status)->before(':')->value();
|
||||||
if ($server_status !== 'running') {
|
if ($server_status !== 'running') {
|
||||||
@@ -565,7 +573,6 @@ class Application extends BaseModel
|
|||||||
|
|
||||||
return $main_server_status;
|
return $main_server_status;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user