Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Remove code for deleting environment

天舟bc028c9cbe28
diff --git a/backend/api/environment.go b/backend/api/environment.go
index 8f707622ff..bf5abfd66c 100644
--- a/backend/api/environment.go
+++ b/backend/api/environment.go
@@ -62,5 +62,4 @@ type EnvironmentService interface {
FindEnvironmentList(ctx context.Context, find *EnvironmentFind) ([]*Environment, error)
FindEnvironment(ctx context.Context, find *EnvironmentFind) (*Environment, error)
PatchEnvironmentByID(ctx context.Context, patch *EnvironmentPatch) (*Environment, error)
- DeleteEnvironmentByID(ctx context.Context, delete *EnvironmentDelete) error
}
diff --git a/backend/server/acl_casbin_policy_dba.csv b/backend/server/acl_casbin_policy_dba.csv
index f5d56627d4..05373b2430 100644
--- a/backend/server/acl_casbin_policy_dba.csv
+++ b/backend/server/acl_casbin_policy_dba.csv
@@ -12,7 +12,6 @@ p, DBA, /project/{projectId}/member/{memberId}, DELETE
p, DBA, /environment, POST
p, DBA, /environment, GET
p, DBA, /environment/{id}, PATCH
-p, DBA, /environment/{id}, DELETE
p, DBA, /instance, POST
p, DBA, /instance, GET
p, DBA, /instance/{id}, GET
diff --git a/backend/server/acl_casbin_policy_owner.csv b/backend/server/acl_casbin_policy_owner.csv
index 35e77536c6..97294352d8 100644
--- a/backend/server/acl_casbin_policy_owner.csv
+++ b/backend/server/acl_casbin_policy_owner.csv
@@ -17,7 +17,6 @@ p, OWNER, /project/{projectId}/member/{memberId}, DELETE
p, OWNER, /environment, POST
p, OWNER, /environment, GET
p, OWNER, /environment/{id}, PATCH
-p, OWNER, /environment/{id}, DELETE
p, OWNER, /instance, POST
p, OWNER, /instance, GET
p, OWNER, /instance/{id}, GET
diff --git a/backend/server/environment.go b/backend/server/environment.go
index 607e62ab31..f845784082 100644
--- a/backend/server/environment.go
+++ b/backend/server/environment.go
@@ -84,29 +84,6 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {
return nil
})
- g.DELETE("/environment/:id", func(c echo.Context) error {
- id, err := strconv.Atoi(c.Param("id"))
- if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
- }
-
- environmentDelete := &api.EnvironmentDelete{
- ID: id,
- DeleterId: c.Get(GetPrincipalIdContextKey()).(int),
- }
- err = s.EnvironmentService.DeleteEnvironmentByID(context.Background(), environmentDelete)
- if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Environment ID not found: %d", id))
- }
- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete environment ID: %v", id)).SetInternal(err)
- }
-
- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
- c.Response().WriteHeader(http.StatusOK)
- return nil
- })
-
g.PATCH("/environment/reorder", func(c echo.Context) error {
patchList, err := jsonapi.UnmarshalManyPayload(c.Request().Body, reflect.TypeOf(new(api.EnvironmentPatch)))
if err != nil {
diff --git a/backend/store/environment.go b/backend/store/environment.go
index bfbabad9bc..45d4e68950 100644
--- a/backend/store/environment.go
+++ b/backend/store/environment.go
@@ -74,7 +74,7 @@ func (s *EnvironmentService) FindEnvironment(ctx context.Context, find *api.Envi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("enviornment not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("environment not found: %v", find)}
} else if len(list) > 1 {
s.l.Warnf("found mulitple environments: %d, expect 1", len(list))
}
@@ -102,27 +102,6 @@ func (s *EnvironmentService) PatchEnvironmentByID(ctx context.Context, patch *ap
return environment, nil
}
-// DeleteEnvironmentByID deletes an existing environment by ID.
-// Returns ENOTFOUND if environment does not exist.
-func (s *EnvironmentService) DeleteEnvironmentByID(ctx context.Context, delete *api.EnvironmentDelete) error {
- tx, err := s.db.BeginTx(ctx, nil)
- if err != nil {
- return FormatError(err)
- }
- defer tx.Rollback()
-
- err = s.deleteEnvironment(ctx, tx, delete)
- if err != nil {
- return FormatError(err)
- }
-
- if err := tx.Commit(); err != nil {
- return FormatError(err)
- }
-
- return nil
-}
-
// createEnvironment creates a new environment.
func (s *EnvironmentService) createEnvironment(ctx context.Context, tx *Tx, create *api.EnvironmentCreate) (*api.Environment, error) {
// The order is the MAX(order) + 1
@@ -298,19 +277,3 @@ func (s *EnvironmentService) patchEnvironment(ctx context.Context, tx *Tx, patch
return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("environment ID not found: %d", patch.ID)}
}
-
-// deleteEnvironment permanently deletes a environment by ID.
-func (s *EnvironmentService) deleteEnvironment(ctx context.Context, tx *Tx, delete *api.EnvironmentDelete) error {
- // Remove row from database.
- result, err := tx.ExecContext(ctx, `DELETE FROM environment WHERE id = ?`, delete.ID)
- if err != nil {
- return FormatError(err)
- }
-
- rows, _ := result.RowsAffected()
- if rows == 0 {
- return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("environment ID not found: %d", delete.ID)}
- }
-
- return nil
-}
diff --git a/frontend/src/miragejs/routes/environment.js b/frontend/src/miragejs/routes/environment.js
index 0a527a356c..260d6efaca 100644
--- a/frontend/src/miragejs/routes/environment.js
+++ b/frontend/src/miragejs/routes/environment.js
@@ -169,34 +169,4 @@ export default function configureEnvironment(route) {
return updatedEnvironment;
});
-
- route.delete("/environment/:environmentId", function (schema, request) {
- const environment = schema.environments.find(request.params.environmentId);
-
- if (!environment) {
- return new Response(
- 404,
- {},
- {
- errors:
- "Environment id " + request.params.environmentId + " not found",
- }
- );
- }
-
- const instanceCount = schema.instances.where({
- environmentId: request.params.environmentId,
- }).models.length;
- if (instanceCount > 0) {
- return new Response(
- 400,
- {},
- {
- errors: `Found ${instanceCount} instance(s) in environment ${environment.name}. Environment can only be deleted if no instance resides under it.`,
- }
- );
- }
-
- environment.destroy();
- });
}
diff --git a/frontend/src/store/modules/environment.ts b/frontend/src/store/modules/environment.ts
index d0d08d0982..4c9c85dfee 100644
--- a/frontend/src/store/modules/environment.ts
+++ b/frontend/src/store/modules/environment.ts
@@ -160,15 +160,6 @@ const actions = {
return updatedEnvironment;
},
-
- async deleteEnvironmentById(
- { commit }: { state: EnvironmentState; commit: any },
- id: EnvironmentId
- ) {
- await axios.delete(`/api/environment/${id}`);
-
- commit("deleteEnvironmentById", id);
- },
};
const mutations = {
@@ -189,16 +180,6 @@ const mutations = {
state.environmentList.sort((a, b) => a.order - b.order);
}
},
-
- deleteEnvironmentById(state: EnvironmentState, environmentId: EnvironmentId) {
- const i = state.environmentList.findIndex(
- (item: Environment) => item.id == environmentId
- );
-
- if (i >= 0) {
- state.environmentList.splice(i, 1);
- }
- },
};
export default {