fix(env): custom environment variable sorting (#7887)

This commit is contained in:
🏔️ Peak 2026-01-06 16:25:28 +01:00 committed by GitHub
commit ffdae66c4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 26 additions and 96 deletions

View file

@ -63,20 +63,30 @@ public function instantSave()
public function getEnvironmentVariablesProperty() public function getEnvironmentVariablesProperty()
{ {
if ($this->is_env_sorting_enabled === false) { $query = $this->resource->environment_variables()
return $this->resource->environment_variables()->orderBy('order')->get(); ->orderByRaw("CASE WHEN is_required = true AND (value IS NULL OR value = '') THEN 0 ELSE 1 END");
if ($this->is_env_sorting_enabled) {
$query->orderBy('key');
} else {
$query->orderBy('order');
} }
return $this->resource->environment_variables; return $query->get();
} }
public function getEnvironmentVariablesPreviewProperty() public function getEnvironmentVariablesPreviewProperty()
{ {
if ($this->is_env_sorting_enabled === false) { $query = $this->resource->environment_variables_preview()
return $this->resource->environment_variables_preview()->orderBy('order')->get(); ->orderByRaw("CASE WHEN is_required = true AND (value IS NULL OR value = '') THEN 0 ELSE 1 END");
if ($this->is_env_sorting_enabled) {
$query->orderBy('key');
} else {
$query->orderBy('order');
} }
return $this->resource->environment_variables_preview; return $query->get();
} }
public function getDevView() public function getDevView()

View file

@ -845,15 +845,7 @@ public function detectPortFromEnvironment(?bool $isPreview = false): ?int
public function environment_variables() public function environment_variables()
{ {
return $this->morphMany(EnvironmentVariable::class, 'resourceable') return $this->morphMany(EnvironmentVariable::class, 'resourceable')
->where('is_preview', false) ->where('is_preview', false);
->orderByRaw("
CASE
WHEN is_required = true THEN 1
WHEN LOWER(key) LIKE 'service_%' THEN 2
ELSE 3
END,
LOWER(key) ASC
");
} }
public function runtime_environment_variables() public function runtime_environment_variables()

View file

@ -1458,15 +1458,7 @@ public function scheduled_tasks(): HasMany
public function environment_variables() public function environment_variables()
{ {
return $this->morphMany(EnvironmentVariable::class, 'resourceable') return $this->morphMany(EnvironmentVariable::class, 'resourceable');
->orderByRaw("
CASE
WHEN is_required = true THEN 1
WHEN LOWER(key) LIKE 'service_%' THEN 2
ELSE 3
END,
LOWER(key) ASC
");
} }
public function workdir() public function workdir()

View file

@ -295,15 +295,7 @@ public function destination()
public function environment_variables() public function environment_variables()
{ {
return $this->morphMany(EnvironmentVariable::class, 'resourceable') return $this->morphMany(EnvironmentVariable::class, 'resourceable');
->orderByRaw("
CASE
WHEN LOWER(key) LIKE 'service_%' THEN 1
WHEN is_required = true AND (value IS NULL OR value = '') THEN 2
ELSE 3
END,
LOWER(key) ASC
");
} }
public function runtime_environment_variables() public function runtime_environment_variables()

View file

@ -324,14 +324,6 @@ public function isBackupSolutionAvailable()
public function environment_variables() public function environment_variables()
{ {
return $this->morphMany(EnvironmentVariable::class, 'resourceable') return $this->morphMany(EnvironmentVariable::class, 'resourceable');
->orderByRaw("
CASE
WHEN LOWER(key) LIKE 'service_%' THEN 1
WHEN is_required = true AND (value IS NULL OR value = '') THEN 2
ELSE 3
END,
LOWER(key) ASC
");
} }
} }

View file

@ -324,14 +324,6 @@ public function isBackupSolutionAvailable()
public function environment_variables() public function environment_variables()
{ {
return $this->morphMany(EnvironmentVariable::class, 'resourceable') return $this->morphMany(EnvironmentVariable::class, 'resourceable');
->orderByRaw("
CASE
WHEN LOWER(key) LIKE 'service_%' THEN 1
WHEN is_required = true AND (value IS NULL OR value = '') THEN 2
ELSE 3
END,
LOWER(key) ASC
");
} }
} }

View file

@ -289,15 +289,7 @@ public function destination(): MorphTo
public function environment_variables() public function environment_variables()
{ {
return $this->morphMany(EnvironmentVariable::class, 'resourceable') return $this->morphMany(EnvironmentVariable::class, 'resourceable');
->orderByRaw("
CASE
WHEN LOWER(key) LIKE 'service_%' THEN 1
WHEN is_required = true AND (value IS NULL OR value = '') THEN 2
ELSE 3
END,
LOWER(key) ASC
");
} }
public function runtime_environment_variables() public function runtime_environment_variables()

View file

@ -349,14 +349,6 @@ public function isBackupSolutionAvailable()
public function environment_variables() public function environment_variables()
{ {
return $this->morphMany(EnvironmentVariable::class, 'resourceable') return $this->morphMany(EnvironmentVariable::class, 'resourceable');
->orderByRaw("
CASE
WHEN LOWER(key) LIKE 'service_%' THEN 1
WHEN is_required = true AND (value IS NULL OR value = '') THEN 2
ELSE 3
END,
LOWER(key) ASC
");
} }
} }

View file

@ -328,14 +328,6 @@ public function isBackupSolutionAvailable()
public function environment_variables() public function environment_variables()
{ {
return $this->morphMany(EnvironmentVariable::class, 'resourceable') return $this->morphMany(EnvironmentVariable::class, 'resourceable');
->orderByRaw("
CASE
WHEN LOWER(key) LIKE 'service_%' THEN 1
WHEN is_required = true AND (value IS NULL OR value = '') THEN 2
ELSE 3
END,
LOWER(key) ASC
");
} }
} }

View file

@ -323,15 +323,7 @@ public function scheduledBackups()
public function environment_variables() public function environment_variables()
{ {
return $this->morphMany(EnvironmentVariable::class, 'resourceable') return $this->morphMany(EnvironmentVariable::class, 'resourceable');
->orderByRaw("
CASE
WHEN LOWER(key) LIKE 'service_%' THEN 1
WHEN is_required = true AND (value IS NULL OR value = '') THEN 2
ELSE 3
END,
LOWER(key) ASC
");
} }
public function isBackupSolutionAvailable() public function isBackupSolutionAvailable()

View file

@ -374,14 +374,6 @@ public function redisUsername(): Attribute
public function environment_variables() public function environment_variables()
{ {
return $this->morphMany(EnvironmentVariable::class, 'resourceable') return $this->morphMany(EnvironmentVariable::class, 'resourceable');
->orderByRaw("
CASE
WHEN LOWER(key) LIKE 'service_%' THEN 1
WHEN is_required = true AND (value IS NULL OR value = '') THEN 2
ELSE 3
END,
LOWER(key) ASC
");
} }
} }