Skip to content

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

feat: extend the fields of the PITR issue context and PITR task payload (#2039)

h3n4lc84f3103408a
diff --git a/api/issue.go b/api/issue.go
index 3d0b664c4c..76468ea6a4 100644
--- a/api/issue.go
+++ b/api/issue.go
@@ -186,12 +186,20 @@ type UpdateSchemaGhostContext struct {
// PITRContext is the issue create context for performing a PITR in a database.
type PITRContext struct {
- DatabaseID int `json:"databaseId"`
+ DatabaseID int `json:"databaseId"`
+
+ // CreateDatabaseCtx will be not nil if user want to restore to a new database.
+ // The new database should be under the same project as the original database.
CreateDatabaseCtx *CreateDatabaseContext `json:"createDatabaseContext"`
+ // BackupID and PointInTimeTs only allow one non-nil.
+
+ // BackupID is not nil if the user just restore a full backup only.
+ BackupID *int `json:"backupId"`
+
// After the PITR operations, the database will be recovered to the state at this time.
// Represented in UNIX timestamp in seconds.
- PointInTimeTs int64 `json:"pointInTimeTs"`
+ PointInTimeTs *int64 `json:"pointInTimeTs"`
}
// IssueFind is the API message for finding issues.
diff --git a/api/task.go b/api/task.go
index f90c74757b..15254ef15c 100644
--- a/api/task.go
+++ b/api/task.go
@@ -68,9 +68,19 @@ const (
type TaskDatabasePITRRestorePayload struct {
// The project owning the database.
ProjectID int `json:"projectId,omitempty"`
+
+ // TargetInstanceId must be within the same environment as the instance of the original database.
+ // Only used when doing PITR to a new database.
+ TargetInstanceID *int `json:"targetInstanceId,omitempty"`
+
+ // BackupID and PointInTimeTs only allow one non-nil.
+
+ // Only used when doing restore full backup only.
+ BackupID *int `json:"backupId,omitempty"`
+
// After the PITR operations, the database will be recovered to the state at this time.
// Represented in UNIX timestamp in seconds.
- PointInTimeTs int64 `json:"pointInTimeTs,omitempty"`
+ PointInTimeTs *int64 `json:"pointInTimeTs,omitempty"`
}
// TaskDatabasePITRCutoverPayload is the task payload for PITR cutover.
diff --git a/server/issue.go b/server/issue.go
index 0ffa82ad64..893d445407 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -583,7 +583,7 @@ func (s *Server) getPipelineCreateForDatabasePITR(ctx context.Context, issueCrea
return nil, echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", c.DatabaseID))
}
- taskCreateList, taskIndexDAGList, err := createPITRTaskList(database, issueCreate.ProjectID, c.PointInTimeTs)
+ taskCreateList, taskIndexDAGList, err := createPITRTaskList(database, issueCreate.ProjectID, *c.PointInTimeTs)
if err != nil {
return nil, err
}
@@ -864,7 +864,7 @@ func createPITRTaskList(database *api.Database, projectID int, targetTs int64) (
// task: create and restore to PITR database
payloadRestore := api.TaskDatabasePITRRestorePayload{
ProjectID: projectID,
- PointInTimeTs: targetTs,
+ PointInTimeTs: &targetTs,
}
bytesRestore, err := json.Marshal(payloadRestore)
if err != nil {
diff --git a/server/task_executor_pitr_restore.go b/server/task_executor_pitr_restore.go
index 818b4e964a..90452711e2 100644
--- a/server/task_executor_pitr_restore.go
+++ b/server/task_executor_pitr_restore.go
@@ -44,7 +44,7 @@ func (exec *PITRRestoreTaskExecutor) RunOnce(ctx context.Context, server *Server
}
defer driver.Close(ctx)
- if err := exec.doPITRRestore(ctx, task, server.store, driver, server.profile.DataDir, payload.PointInTimeTs, server.profile.Mode); err != nil {
+ if err := exec.doPITRRestore(ctx, task, server.store, driver, server.profile.DataDir, *payload.PointInTimeTs, server.profile.Mode); err != nil {
log.Error("Failed to do PITR restore", zap.Error(err))
return true, nil, err
}
diff --git a/tests/backup_restore_test.go b/tests/backup_restore_test.go
index 99c0b0fc6a..1681bc849d 100644
--- a/tests/backup_restore_test.go
+++ b/tests/backup_restore_test.go
@@ -405,7 +405,7 @@ func TestPITR(t *testing.T) {
func createPITRIssue(ctl *controller, project *api.Project, database *api.Database, targetTs int64) (*api.Issue, error) {
pitrIssueCtx, err := json.Marshal(&api.PITRContext{
DatabaseID: database.ID,
- PointInTimeTs: targetTs,
+ PointInTimeTs: &targetTs,
})
if err != nil {
return nil, err