forked from coollabsio/coolify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.php
More file actions
179 lines (154 loc) · 6.01 KB
/
Copy pathProject.php
File metadata and controls
179 lines (154 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
namespace App\Models;
use App\Traits\ClearsGlobalSearchCache;
use App\Traits\HasSafeStringAttribute;
use OpenApi\Attributes as OA;
use Visus\Cuid2\Cuid2;
#[OA\Schema(
description: 'Project model',
type: 'object',
properties: [
'id' => ['type' => 'integer'],
'uuid' => ['type' => 'string'],
'name' => ['type' => 'string'],
'description' => ['type' => 'string'],
'environments' => new OA\Property(
property: 'environments',
type: 'array',
items: new OA\Items(ref: '#/components/schemas/Environment'),
description: 'The environments of the project.'
),
]
)]
/**
* @property int $id
* @property string $uuid
* @property string $name
* @property string|null $description
* @property int $team_id
* @property \Illuminate\Database\Eloquent\Collection<int, Environment> $environments
* @property \Illuminate\Database\Eloquent\Collection<int, SharedEnvironmentVariable> $environment_variables
* @property ProjectSetting|null $settings
* @property Team $team
* @property \Illuminate\Database\Eloquent\Collection<int, Service> $services
* @property \Illuminate\Database\Eloquent\Collection<int, Application> $applications
*/
class Project extends BaseModel
{
use ClearsGlobalSearchCache;
use HasSafeStringAttribute;
protected $guarded = [];
/**
* @param array<int, string> $select
* @return \Illuminate\Database\Eloquent\Builder<Project>
*/
public static function ownedByCurrentTeam(array $select = ['*']): \Illuminate\Database\Eloquent\Builder
{
$selectArray = collect($select)->concat(['id']);
return Project::whereTeamId(currentTeam()->id)->select($selectArray->all())->orderByRaw('LOWER(name)');
}
protected static function booted()
{
static::created(function ($project) {
ProjectSetting::create([
'project_id' => $project->id,
]);
Environment::create([
'name' => 'production',
'project_id' => $project->id,
'uuid' => (string) new Cuid2,
]);
});
static::deleting(function ($project) {
$project->environments()->delete();
$project->settings()->delete();
$shared_variables = $project->environment_variables();
foreach ($shared_variables as $shared_variable) {
$shared_variable->delete();
}
});
}
public function environment_variables(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(SharedEnvironmentVariable::class);
}
public function environments(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Environment::class);
}
public function settings(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(ProjectSetting::class);
}
public function team(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Team::class);
}
public function services(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(Service::class, Environment::class);
}
public function applications(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(Application::class, Environment::class);
}
public function postgresqls(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(StandalonePostgresql::class, Environment::class);
}
public function redis(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(StandaloneRedis::class, Environment::class);
}
public function keydbs(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(StandaloneKeydb::class, Environment::class);
}
public function dragonflies(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(StandaloneDragonfly::class, Environment::class);
}
public function clickhouses(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(StandaloneClickhouse::class, Environment::class);
}
public function mongodbs(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(StandaloneMongodb::class, Environment::class);
}
public function mysqls(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(StandaloneMysql::class, Environment::class);
}
public function mariadbs(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->hasManyThrough(StandaloneMariadb::class, Environment::class);
}
public function isEmpty()
{
return $this->applications()->count() == 0 &&
$this->redis()->count() == 0 &&
$this->postgresqls()->count() == 0 &&
$this->mysqls()->count() == 0 &&
$this->keydbs()->count() == 0 &&
$this->dragonflies()->count() == 0 &&
$this->clickhouses()->count() == 0 &&
$this->mariadbs()->count() == 0 &&
$this->mongodbs()->count() == 0 &&
$this->services()->count() == 0;
}
public function databases()
{
return $this->postgresqls()->get()->merge($this->redis()->get())->merge($this->mongodbs()->get())->merge($this->mysqls()->get())->merge($this->mariadbs()->get())->merge($this->keydbs()->get())->merge($this->dragonflies()->get())->merge($this->clickhouses()->get());
}
public function navigateTo()
{
if ($this->environments->count() === 1) {
return route('project.resource.index', [
'project_uuid' => $this->uuid,
'environment_uuid' => $this->environments->first()->uuid,
]);
}
return route('project.show', ['project_uuid' => $this->uuid]);
}
}