mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-15 19:05:28 +02:00
feat(environment): introduce isDefault flag for environments
- Added `isDefault` boolean column to the environment schema, defaulting to false. - Updated environment creation and deletion logic to handle default environments, allowing the production environment to be created and renamed. - Enhanced error handling for environment updates and deletions to prevent modifications to default environments. - Updated UI components to reflect changes in environment selection based on the new default logic.
This commit is contained in:
@@ -103,10 +103,10 @@ export const findEnvironmentsByProjectId = async (projectId: string) => {
|
||||
|
||||
export const deleteEnvironment = async (environmentId: string) => {
|
||||
const currentEnvironment = await findEnvironmentById(environmentId);
|
||||
if (currentEnvironment.name === "production") {
|
||||
if (currentEnvironment.isDefault) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "You cannot delete the production environment",
|
||||
message: "You cannot delete the default environment",
|
||||
});
|
||||
}
|
||||
const deletedEnvironment = await db
|
||||
@@ -162,9 +162,23 @@ export const duplicateEnvironment = async (
|
||||
};
|
||||
|
||||
export const createProductionEnvironment = async (projectId: string) => {
|
||||
return createEnvironment({
|
||||
name: "production",
|
||||
description: "Production environment",
|
||||
projectId,
|
||||
});
|
||||
const newEnvironment = await db
|
||||
.insert(environments)
|
||||
.values({
|
||||
name: "production",
|
||||
description: "Production environment",
|
||||
projectId,
|
||||
isDefault: true,
|
||||
})
|
||||
.returning()
|
||||
.then((value) => value[0]);
|
||||
|
||||
if (!newEnvironment) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Error creating the production environment",
|
||||
});
|
||||
}
|
||||
|
||||
return newEnvironment;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user