Skip to content

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

feat: allow users to editor statement for tenant project create database task (#1419)

Danny Xu6e9a58b9bd53
diff --git a/frontend/src/components/Issue/logic/common.ts b/frontend/src/components/Issue/logic/common.ts
index 9c0bf4a9fb..e6bb5c6e18 100644
--- a/frontend/src/components/Issue/logic/common.ts
+++ b/frontend/src/components/Issue/logic/common.ts
@@ -86,9 +86,13 @@ export const useCommonLogic = () => {
const issueEntity = issue.value as Issue;
- // For Create DB issues ,statement is not editable.
- // Since the server-side seems won't do a patch really.
if (issueEntity.type === "bb.issue.database.create") {
+ // We allow to edit create database statement for tenant project to give users a
+ // chance to edit the dumped schema from its peer databases, because the dumpped schema
+ // may not be pefectly correct.
+ if (issueEntity.project.tenantMode === "TENANT") {
+ return true;
+ }
return false;
}
diff --git a/server/task.go b/server/task.go
index c017017092..f46623be56 100644
--- a/server/task.go
+++ b/server/task.go
@@ -77,8 +77,8 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch project with ID[%d]", issue.ProjectID)).SetInternal(err)
}
- if project.TenantMode == api.TenantModeTenant {
- err := fmt.Errorf("cannot update SQL statement for projects in tenant mode")
+ if project.TenantMode == api.TenantModeTenant && task.Type == api.TaskDatabaseSchemaUpdate {
+ err := fmt.Errorf("cannot update schema update SQL statement for projects in tenant mode")
return echo.NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
}
@@ -105,7 +105,6 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
payloadStr := string(bytes)
taskPatch.Payload = &payloadStr
case api.TaskDatabaseDataUpdate:
-
payload := &api.TaskDatabaseDataUpdatePayload{}
if err := json.Unmarshal([]byte(task.Payload), payload); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Malformed database data update payload").SetInternal(err)
@@ -121,7 +120,22 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
}
payloadStr := string(bytes)
taskPatch.Payload = &payloadStr
-
+ case api.TaskDatabaseCreate:
+ payload := &api.TaskDatabaseCreatePayload{}
+ if err := json.Unmarshal([]byte(task.Payload), payload); err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, "Malformed database create payload").SetInternal(err)
+ }
+ oldStatement = payload.Statement
+ payload.Statement = *taskPatch.Statement
+ // We should update the schema version if we've updated the SQL, otherwise we will
+ // get migration history version conflict if the previous task has been attempted.
+ payload.SchemaVersion = common.DefaultMigrationVersion()
+ bytes, err := json.Marshal(payload)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to construct updated task payload").SetInternal(err)
+ }
+ payloadStr := string(bytes)
+ taskPatch.Payload = &payloadStr
}
}