dev-preprod-prod logic

This commit is contained in:
2026-03-01 14:39:25 +03:00
parent 165f91b399
commit b7960344e0
13 changed files with 754 additions and 70 deletions

View File

@@ -74,8 +74,8 @@
url: "",
username: "",
password: "",
stage: "DEV",
is_default: false,
is_production: false,
backup_schedule: {
enabled: false,
cron_expression: "0 0 * * *",
@@ -356,8 +356,13 @@
if (!newEnv.backup_schedule) {
newEnv.backup_schedule = { enabled: false, cron_expression: "0 0 * * *" };
}
if (typeof newEnv.is_production !== "boolean") {
newEnv.is_production = false;
const rawStage = String(newEnv.stage || "").toUpperCase();
if (rawStage === "DEV" && newEnv.is_production === true) {
newEnv.stage = "PROD";
} else if (!rawStage) {
newEnv.stage = newEnv.is_production ? "PROD" : "DEV";
} else {
newEnv.stage = rawStage;
}
editingEnvId = env.id;
isAddingEnv = false;
@@ -370,8 +375,8 @@
url: "",
username: "",
password: "",
stage: "DEV",
is_default: false,
is_production: false,
backup_schedule: {
enabled: false,
cron_expression: "0 0 * * *",
@@ -392,11 +397,17 @@
return;
}
const payload = {
...newEnv,
stage: String(newEnv.stage || "DEV").toUpperCase(),
is_production: String(newEnv.stage || "DEV").toUpperCase() === "PROD",
};
if (editingEnvId) {
await api.updateEnvironment(editingEnvId, newEnv);
await api.updateEnvironment(editingEnvId, payload);
addToast($t.settings?.env_updated, "success");
} else {
await api.addEnvironment(newEnv);
await api.addEnvironment(payload);
addToast($t.settings?.env_added, "success");
}
@@ -429,6 +440,10 @@
}
}
}
function resolveEnvStage(env) {
return String((env?.is_production ? "PROD" : env?.stage) || "DEV").toUpperCase();
}
</script>
<div class="mx-auto w-full max-w-7xl space-y-6">
@@ -679,19 +694,21 @@
>{$t.settings?.env_default}</label
>
</div>
<div class="flex items-center mt-6">
<input
type="checkbox"
id="env_production"
bind:checked={newEnv.is_production}
class="h-4 w-4 text-red-600 border-gray-300 rounded"
/>
<div>
<label
for="env_production"
class="ml-2 block text-sm font-medium text-red-700"
>{$t.settings?.env_production ||
"Production environment"}</label
for="env_stage"
class="block text-sm font-medium text-gray-700"
>Stage</label
>
<select
id="env_stage"
bind:value={newEnv.stage}
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2"
>
<option value="DEV">DEV</option>
<option value="PREPROD">PREPROD</option>
<option value="PROD">PROD</option>
</select>
</div>
</div>
@@ -777,7 +794,7 @@
>
<th
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>{$t.settings?.env_production || "Production"}</th
>Stage</th
>
<th
class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider"
@@ -804,15 +821,10 @@
{/if}
</td>
<td class="px-6 py-4 whitespace-nowrap">
{#if env.is_production}
<span
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800"
>
PROD
</span>
{:else}
<span class="text-gray-500">{$t.common?.no}</span>
{/if}
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full
{resolveEnvStage(env) === 'PROD' ? 'bg-red-100 text-red-800' : resolveEnvStage(env) === 'PREPROD' ? 'bg-amber-100 text-amber-800' : 'bg-blue-100 text-blue-800'}">
{resolveEnvStage(env)}
</span>
</td>
<td
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"