2023-09-20 13:42:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
|
|
|
class ServiceDatabase extends BaseModel
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
|
2023-11-06 17:04:18 +00:00
|
|
|
protected static function booted()
|
|
|
|
{
|
|
|
|
static::deleting(function ($service) {
|
|
|
|
$service->persistentStorages()->delete();
|
|
|
|
$service->fileStorages()->delete();
|
|
|
|
});
|
|
|
|
}
|
2023-09-22 09:23:49 +00:00
|
|
|
public function type()
|
|
|
|
{
|
|
|
|
return 'service';
|
|
|
|
}
|
2023-11-13 14:19:49 +00:00
|
|
|
public function serviceType()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2023-11-07 11:11:47 +00:00
|
|
|
public function databaseType()
|
|
|
|
{
|
|
|
|
$image = str($this->image)->before(':');
|
|
|
|
if ($image->value() === 'postgres') {
|
|
|
|
$image = 'postgresql';
|
|
|
|
}
|
|
|
|
return "standalone-$image";
|
|
|
|
}
|
2023-11-13 14:19:49 +00:00
|
|
|
public function getServiceDatabaseUrl()
|
|
|
|
{
|
2023-11-09 13:59:38 +00:00
|
|
|
$port = $this->public_port;
|
2023-11-09 14:05:42 +00:00
|
|
|
$realIp = $this->service->server->ip;
|
|
|
|
if ($realIp === 'host.docker.internal' || isDev()) {
|
|
|
|
$realIp = base_ip();
|
|
|
|
}
|
|
|
|
$url = "{$realIp}:{$port}";
|
2023-11-09 13:59:38 +00:00
|
|
|
return $url;
|
|
|
|
}
|
2023-09-22 10:08:51 +00:00
|
|
|
public function service()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Service::class);
|
|
|
|
}
|
2023-09-22 09:23:49 +00:00
|
|
|
public function persistentStorages()
|
|
|
|
{
|
|
|
|
return $this->morphMany(LocalPersistentVolume::class, 'resource');
|
|
|
|
}
|
2023-09-25 10:49:55 +00:00
|
|
|
public function fileStorages()
|
|
|
|
{
|
|
|
|
return $this->morphMany(LocalFileVolume::class, 'resource');
|
|
|
|
}
|
2023-10-02 16:02:32 +00:00
|
|
|
public function getFilesFromServer(bool $isInit = false)
|
2023-09-25 10:49:55 +00:00
|
|
|
{
|
2023-10-02 16:02:32 +00:00
|
|
|
getFilesystemVolumesFromServer($this, $isInit);
|
2023-09-25 10:49:55 +00:00
|
|
|
}
|
2023-11-07 11:11:47 +00:00
|
|
|
public function scheduledBackups()
|
|
|
|
{
|
|
|
|
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
|
|
|
|
}
|
2023-09-20 13:42:41 +00:00
|
|
|
}
|