Skip to content

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

Restore database task should not create the databse metadata entry...

天舟14f7eef8107e
diff --git a/api/task.go b/api/task.go
index bc7644d34e..42da953314 100644
--- a/api/task.go
+++ b/api/task.go
@@ -76,13 +76,9 @@ type TaskDatabaseBackupPayload struct {
// TaskDatabaseRestorePayload is the task payload for database restore.
type TaskDatabaseRestorePayload struct {
- // The project owning the database.
- ProjectId int `json:"projectId,omitempty"`
// The database name we restore to. When we restore a backup to a new database, we only have the database name
// and don't have the database id upon constructing the task yet.
DatabaseName string `json:"databaseName,omitempty"`
- CharacterSet string `json:"character,omitempty"`
- Collation string `json:"collation,omitempty"`
BackupId int `json:"backupId,omitempty"`
}
diff --git a/frontend/src/components/CreateDatabasePrepForm.vue b/frontend/src/components/CreateDatabasePrepForm.vue
index 6ca0dbd886..17fa5e528c 100644
--- a/frontend/src/components/CreateDatabasePrepForm.vue
+++ b/frontend/src/components/CreateDatabasePrepForm.vue
@@ -323,8 +323,6 @@ export default {
statement: "",
rollbackStatement: "",
databaseName: state.databaseName,
- characterSet: state.characterSet,
- collation: state.collation,
backupId: props.backup.id,
},
],
diff --git a/server/issue.go b/server/issue.go
index c5ed6c51b8..ef03350dc6 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -342,12 +342,6 @@ func (s *Server) CreateIssue(ctx context.Context, issueCreate *api.IssueCreate,
if taskCreate.DatabaseName == "" {
return nil, fmt.Errorf("failed to create restore database task, database name missing")
}
- if taskCreate.CharacterSet == "" {
- return nil, fmt.Errorf("failed to create restore database task, character set missing")
- }
- if taskCreate.Collation == "" {
- return nil, fmt.Errorf("failed to create restore database task, collation missing")
- }
if taskCreate.BackupId == nil {
return nil, fmt.Errorf("failed to create restore database task, backup missing")
}
@@ -402,8 +396,6 @@ func (s *Server) CreateIssue(ctx context.Context, issueCreate *api.IssueCreate,
} else if taskCreate.Type == api.TaskDatabaseRestore {
payload := api.TaskDatabaseRestorePayload{}
payload.DatabaseName = taskCreate.DatabaseName
- payload.CharacterSet = taskCreate.CharacterSet
- payload.Collation = taskCreate.Collation
payload.BackupId = *taskCreate.BackupId
bytes, err := json.Marshal(payload)
if err != nil {
diff --git a/server/task.go b/server/task.go
index 79873b2b3c..1c9cc775ad 100644
--- a/server/task.go
+++ b/server/task.go
@@ -259,38 +259,21 @@ func (s *Server) ChangeTaskStatusWithPatch(ctx context.Context, task *api.Task,
// 1. Assign the proper project to the newly created database. Otherwise, the periodic schema
// sync will place the synced db into the default project.
// 2. Allow user to see the created database right away.
- if (updatedTask.Type == api.TaskDatabaseCreate || updatedTask.Type == api.TaskDatabaseRestore) &&
+ if (updatedTask.Type == api.TaskDatabaseCreate) &&
updatedTask.Status == api.TaskDone {
- var projectId int
- var databaseName, characterSet, collation string
- if updatedTask.Type == api.TaskDatabaseCreate {
- payload := &api.TaskDatabaseCreatePayload{}
- if err := json.Unmarshal([]byte(updatedTask.Payload), payload); err != nil {
- return nil, fmt.Errorf("invalid create database task payload: %w", err)
- }
- projectId = payload.ProjectId
- databaseName = payload.DatabaseName
- characterSet = payload.CharacterSet
- collation = payload.Collation
- } else {
- payload := &api.TaskDatabaseRestorePayload{}
- if err := json.Unmarshal([]byte(updatedTask.Payload), payload); err != nil {
- return nil, fmt.Errorf("invalid create database task payload: %w", err)
- }
- projectId = payload.ProjectId
- databaseName = payload.DatabaseName
- characterSet = payload.CharacterSet
- collation = payload.Collation
+ payload := &api.TaskDatabaseCreatePayload{}
+ if err := json.Unmarshal([]byte(updatedTask.Payload), payload); err != nil {
+ return nil, fmt.Errorf("invalid create database task payload: %w", err)
}
z, offset := time.Now().Zone()
databaseCreate := &api.DatabaseCreate{
CreatorId: taskStatusPatch.UpdaterId,
- ProjectId: projectId,
+ ProjectId: payload.ProjectId,
InstanceId: task.InstanceId,
- Name: databaseName,
- CharacterSet: characterSet,
- Collation: collation,
+ Name: payload.DatabaseName,
+ CharacterSet: payload.CharacterSet,
+ Collation: payload.Collation,
TimezoneName: z,
TimezoneOffset: offset,
}
@@ -299,8 +282,8 @@ func (s *Server) ChangeTaskStatusWithPatch(ctx context.Context, task *api.Task,
// Just emits an error instead of failing, since we have another periodic job to sync db info.
// Though the db will be assigned to the default project instead of the desired project in that case.
s.l.Error("failed to record database after creating database",
- zap.String("database_name", databaseName),
- zap.Int("project_id", projectId),
+ zap.String("database_name", payload.DatabaseName),
+ zap.Int("project_id", payload.ProjectId),
zap.Int("instance_id", task.InstanceId),
zap.Error(err),
)
@@ -310,13 +293,15 @@ func (s *Server) ChangeTaskStatusWithPatch(ctx context.Context, task *api.Task,
// If this is the last task in the pipeline and just completed, and the assignee is system bot:
// Case 1: If the task is associated with an issue, then we mark the issue (including the pipeline) as DONE.
// Case 2: If the task is NOT associated with an issue, then we mark the pipeline as DONE.
+ fmt.Printf("status %v, assignee %v\n", updatedTask.Status, issue.AssigneeId)
if updatedTask.Status == "DONE" && issue.AssigneeId == api.SYSTEM_BOT_ID {
- pipeline, err := s.ComposePipelineById(ctx, task.PipelineId)
+ pipeline, err := s.ComposePipelineById(ctx, updatedTask.PipelineId)
if err != nil {
- return nil, fmt.Errorf("failed to fetch pipeline to mark issue %v as DONE after completing task %v", issue.Name, updatedTask.Name)
+ return nil, fmt.Errorf("failed to fetch pipeline/issue as DONE after completing task %v", updatedTask.Name)
}
lastStage := pipeline.StageList[len(issue.Pipeline.StageList)-1]
- if lastStage.TaskList[len(lastStage.TaskList)-1].ID == task.ID {
+ fmt.Printf("last %v, me %v\n", lastStage.TaskList[len(lastStage.TaskList)-1].ID, updatedTask.ID)
+ if lastStage.TaskList[len(lastStage.TaskList)-1].ID == updatedTask.ID {
if issue == nil {
status := api.Pipeline_Done
pipelinePatch := &api.PipelinePatch{