Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: cleanup legacy backup setting (#6518)
ecmadaof9a31ec43569
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.goindex 430939af83..bd5c5d8086 100644--- a/backend/api/v1/database_service.go+++ b/backend/api/v1/database_service.go@@ -436,7 +436,7 @@ func (s *DatabaseService) UpdateBackupSetting(ctx context.Context, request *v1pbif database == nil {return nil, status.Errorf(codes.NotFound, "database %q not found", databaseName)}- backupSetting, err := validateAndConvertToStoreBackupSetting(request.Setting, database.UID)+ backupSetting, err := s.validateAndConvertToStoreBackupSetting(ctx, request.Setting, database)if err != nil {return nil, status.Errorf(codes.InvalidArgument, err.Error())}@@ -1563,7 +1563,7 @@ func convertToBackupSetting(backupSetting *store.BackupSettingMessage, instanceI}, nil}-func validateAndConvertToStoreBackupSetting(backupSetting *v1pb.BackupSetting, databaseUID int) (*store.BackupSettingMessage, error) {+func (s *DatabaseService) validateAndConvertToStoreBackupSetting(ctx context.Context, backupSetting *v1pb.BackupSetting, database *store.DatabaseMessage) (*store.BackupSettingMessage, error) {enable := backupSetting.CronSchedule != ""hourOfDay := 0dayOfWeek := -1@@ -1578,14 +1578,46 @@ func validateAndConvertToStoreBackupSetting(backupSetting *v1pb.BackupSetting, dif err != nil {return nil, err}- return &store.BackupSettingMessage{- DatabaseUID: databaseUID,+ setting := &store.BackupSettingMessage{+ DatabaseUID: database.UID,Enabled: enable,HourOfDay: hourOfDay,DayOfWeek: dayOfWeek,RetentionPeriodTs: periodTs,HookURL: backupSetting.HookUrl,- }, nil+ }++ environment, err := s.store.GetEnvironmentV2(ctx, &store.FindEnvironmentMessage{+ ResourceID: &database.EnvironmentID,+ ShowDeleted: true,+ })+ if err != nil {+ return nil, status.Errorf(codes.Internal, err.Error())+ }+ if environment == nil {+ return nil, status.Errorf(codes.NotFound, "environment %q not found", database.EnvironmentID)+ }+ backupPlanPolicy, err := s.store.GetBackupPlanPolicyByEnvID(ctx, environment.UID)+ if err != nil {+ return nil, status.Errorf(codes.Internal, err.Error())+ }+ if backupPlanPolicy.Schedule != api.BackupPlanPolicyScheduleUnset {+ if !setting.Enabled {+ return nil, &common.Error{Code: common.Invalid, Err: errors.Errorf("backup setting should not be disabled for backup plan policy schedule %q", backupPlanPolicy.Schedule)}+ }+ switch backupPlanPolicy.Schedule {+ case api.BackupPlanPolicyScheduleDaily:+ if setting.DayOfWeek != -1 {+ return nil, &common.Error{Code: common.Invalid, Err: errors.Errorf("backup setting DayOfWeek should be unset for backup plan policy schedule %q", backupPlanPolicy.Schedule)}+ }+ case api.BackupPlanPolicyScheduleWeekly:+ if setting.DayOfWeek == -1 {+ return nil, &common.Error{Code: common.Invalid, Err: errors.Errorf("backup setting DayOfWeek should be set for backup plan policy schedule %q", backupPlanPolicy.Schedule)}+ }+ }+ }++ return setting, nil}// parseSimpleCron parses a simple cron expression(only support hour of day and day of week), and returns them as int.diff --git a/backend/legacyapi/backup.go b/backend/legacyapi/backup.goindex b4b24e98aa..a33e093b02 100644--- a/backend/legacyapi/backup.go+++ b/backend/legacyapi/backup.go@@ -107,50 +107,3 @@ type BackupCreate struct {MigrationHistoryVersion stringPath string}--// BackupSetting is the backup setting for a database.-type BackupSetting struct {- ID int `jsonapi:"primary,backupSetting"`-- UpdatedTs int64-- // Related fields- DatabaseID int `jsonapi:"attr,databaseId"`-- // Domain specific fields- Enabled bool `jsonapi:"attr,enabled"`- // Schedule related fields- Hour int `jsonapi:"attr,hour"`- DayOfWeek int `jsonapi:"attr,dayOfWeek"`- // RetentionPeriodTs is the period that backup data is kept for the database.- // 0 means unset and we do not delete data.- RetentionPeriodTs int `jsonapi:"attr,retentionPeriodTs"`- // HookURL is the callback url to be requested (using HTTP GET) after a successful backup.- HookURL string `jsonapi:"attr,hookUrl"`-}--// BackupSettingUpsert is the message to upsert a backup settings.-// NOTE: We use PATCH for Upsert, this is inspired by https://google.aip.dev/134#patch-and-put-type BackupSettingUpsert struct {- // Standard fields- // Value is assigned from the jwt subject field passed by the client.- // CreatorID is the ID of the creator.- UpdaterID int-- // Related fields- DatabaseID int `jsonapi:"attr,databaseId"`- EnvironmentID int-- // Domain specific fields- Enabled bool `jsonapi:"attr,enabled"`- Hour int `jsonapi:"attr,hour"`- DayOfWeek int `jsonapi:"attr,dayOfWeek"`- RetentionPeriodTs int `jsonapi:"attr,retentionPeriodTs"`- HookURL string `jsonapi:"attr,hookUrl"`-}--// BackupSettingsMatch is the message to find backup settings matching the conditions.-type BackupSettingsMatch struct {- Hour int- DayOfWeek int-}diff --git a/backend/runner/backuprun/runner.go b/backend/runner/backuprun/runner.goindex dd0ebf779c..cb042aebfc 100644--- a/backend/runner/backuprun/runner.go+++ b/backend/runner/backuprun/runner.go@@ -310,21 +310,20 @@ func (r *Runner) downloadBinlogFilesForInstance(ctx context.Context, instance *sfunc (r *Runner) startAutoBackups(ctx context.Context) {// Find all databases that need a backup in this hour.t := time.Now().UTC().Truncate(time.Hour)- match := &api.BackupSettingsMatch{+ backupSettingList, err := r.store.FindBackupSettingsMatch(ctx, &store.BackupSettingsMatchMessage{Hour: t.Hour(),DayOfWeek: int(t.Weekday()),- }- backupSettingList, err := r.store.FindBackupSettingsMatch(ctx, match)+ })if err != nil {log.Error("Failed to retrieve backup settings match", zap.Error(err))return}for _, backupSetting := range backupSettingList {- if _, ok := r.stateCfg.RunningBackupDatabases.Load(backupSetting.DatabaseID); ok {+ if _, ok := r.stateCfg.RunningBackupDatabases.Load(backupSetting.DatabaseUID); ok {continue}- database, err := r.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{UID: &backupSetting.DatabaseID})+ database, err := r.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{UID: &backupSetting.DatabaseUID})if err != nil {log.Error("Failed to get database", zap.Error(err))return@@ -371,7 +370,7 @@ func (r *Runner) startAutoBackups(ctx context.Context) {continue}- r.stateCfg.RunningBackupDatabases.Store(backupSetting.DatabaseID, true)+ r.stateCfg.RunningBackupDatabases.Store(backupSetting.DatabaseUID, true)go func(database *store.DatabaseMessage, backupName string, hookURL string) {defer func() {r.stateCfg.RunningBackupDatabases.Delete(database.UID)diff --git a/backend/server/acl_casbin_policy_dba.csv b/backend/server/acl_casbin_policy_dba.csvindex a355e733e9..bc6bc3d09c 100644--- a/backend/server/acl_casbin_policy_dba.csv+++ b/backend/server/acl_casbin_policy_dba.csv@@ -60,8 +60,6 @@ p, DBA, /database/{databaseID}/schema, GETp, DBA, /database/{databaseID}/edit, POSTp, DBA, /database/{databaseID}/backup, GETp, DBA, /database/{databaseID}/backup, POST-p, DBA, /database/{databaseID}/backup-setting, GET-p, DBA, /database/{databaseID}/backup-setting, PATCHp, DBA, /database/{databaseID}/data-source, POSTp, DBA, /database/{databaseID}/data-source/{dataSourceID}, GETp, DBA, /database/{databaseID}/data-source/{dataSourceID}, PATCHdiff --git a/backend/server/acl_casbin_policy_developer.csv b/backend/server/acl_casbin_policy_developer.csvindex ad84f5cfba..0f317d02f3 100644--- a/backend/server/acl_casbin_policy_developer.csv+++ b/backend/server/acl_casbin_policy_developer.csv@@ -48,8 +48,6 @@ p, DEVELOPER, /database/{databaseID}/schema, GETp, DEVELOPER, /database/{databaseID}/edit, POSTp, DEVELOPER, /database/{databaseID}/backup, GETp, DEVELOPER, /database/{databaseID}/backup, POST-p, DEVELOPER, /database/{databaseID}/backup-setting, GET-p, DEVELOPER, /database/{databaseID}/backup-setting, PATCHp, DEVELOPER, /database/{databaseID}/data-source, POSTp, DEVELOPER, /database/{databaseID}/data-source/{dataSourceID}, GETp, DEVELOPER, /database/{databaseID}/data-source/{dataSourceID}, PATCHdiff --git a/backend/server/acl_casbin_policy_owner.csv b/backend/server/acl_casbin_policy_owner.csvindex 15af86e12d..8ed1cf3224 100644--- a/backend/server/acl_casbin_policy_owner.csv+++ b/backend/server/acl_casbin_policy_owner.csv@@ -63,8 +63,6 @@ p, OWNER, /database/{databaseID}/schema, GETp, OWNER, /database/{databaseID}/edit, POSTp, OWNER, /database/{databaseID}/backup, GETp, OWNER, /database/{databaseID}/backup, POST-p, OWNER, /database/{databaseID}/backup-setting, GET-p, OWNER, /database/{databaseID}/backup-setting, PATCHp, OWNER, /database/{databaseID}/data-source, POSTp, OWNER, /database/{databaseID}/data-source/{dataSourceID}, GETp, OWNER, /database/{databaseID}/data-source/{dataSourceID}, PATCHdiff --git a/backend/server/database.go b/backend/server/database.goindex c8a27e0449..f7e7e38d20 100644--- a/backend/server/database.go+++ b/backend/server/database.go@@ -11,7 +11,6 @@ import ("github.com/labstack/echo/v4""google.golang.org/protobuf/encoding/protojson"- "github.com/bytebase/bytebase/backend/common"api "github.com/bytebase/bytebase/backend/legacyapi""github.com/bytebase/bytebase/backend/plugin/db"parser "github.com/bytebase/bytebase/backend/plugin/parser/sql"@@ -103,81 +102,6 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {return nil})- g.PATCH("/database/:databaseID/backup-setting", func(c echo.Context) error {- ctx := c.Request().Context()- id, err := strconv.Atoi(c.Param("databaseID"))- if err != nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("databaseID"))).SetInternal(err)- }-- backupSettingUpsert := &api.BackupSettingUpsert{}- if err := jsonapi.UnmarshalPayload(c.Request().Body, backupSettingUpsert); err != nil {- return echo.NewHTTPError(http.StatusBadRequest, "Malformed set backup setting request").SetInternal(err)- }- backupSettingUpsert.UpdaterID = c.Get(getPrincipalIDContextKey()).(int)-- database, err := s.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{UID: &id})- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch database ID: %v", id)).SetInternal(err)- }- if database == nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("database %d not found", id)).SetInternal(err)- }- environment, err := s.store.GetEnvironmentV2(ctx, &store.FindEnvironmentMessage{ResourceID: &database.EnvironmentID})- if err != nil {- return err- }- backupSettingUpsert.EnvironmentID = environment.UID-- backupSetting, err := s.store.UpsertBackupSetting(ctx, backupSettingUpsert)- if err != nil {- if common.ErrorCode(err) == common.Invalid {- return echo.NewHTTPError(http.StatusBadRequest, "Invalid backup setting").SetInternal(err)- }- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to set backup setting").SetInternal(err)- }-- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, backupSetting); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create set backup setting response").SetInternal(err)- }- return nil- })-- g.GET("/database/:databaseID/backup-setting", func(c echo.Context) error {- ctx := c.Request().Context()- id, err := strconv.Atoi(c.Param("databaseID"))- if err != nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("databaseID"))).SetInternal(err)- }-- database, err := s.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{UID: &id})- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch database ID: %v", id)).SetInternal(err)- }- if database == nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("database %d not found", id)).SetInternal(err)- }-- backupSetting, err := s.store.GetBackupSettingV2(ctx, id)- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to get backup setting for database id: %d", id)).SetInternal(err)- }- // Returns the backup setting with UNKNOWN_ID to indicate the database has no backup- apiBackupSetting := &api.BackupSetting{- ID: api.UnknownID,- }- if backupSetting != nil {- apiBackupSetting = backupSetting.ToAPIBackupSetting()- }-- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, apiBackupSetting); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal get backup setting response: %v", id)).SetInternal(err)- }- return nil- })-g.POST("/database/:databaseID/edit", func(c echo.Context) error {ctx := c.Request().Context()databaseID, err := strconv.Atoi(c.Param("databaseID"))diff --git a/backend/store/backup.go b/backend/store/backup.goindex 3fe784d4af..269c4e326b 100644--- a/backend/store/backup.go+++ b/backend/store/backup.go@@ -14,169 +14,24 @@ import (api "github.com/bytebase/bytebase/backend/legacyapi")-// backupSettingRaw is the store model for an BackupSetting.-// Fields have exactly the same meanings as BackupSetting.-type backupSettingRaw struct {- ID int-- UpdatedTs int64-- // Related fields- DatabaseID int-- // Domain specific fields- Enabled bool- Hour int- DayOfWeek int- RetentionPeriodTs int- // HookURL is the callback url to be requested (using HTTP GET) after a successful backup.- HookURL string-}--// toBackupSetting creates an instance of BackupSetting based on the backupSettingRaw.-// This is intended to be called when we need to compose an BackupSetting relationship.-func (raw *backupSettingRaw) toBackupSetting() *api.BackupSetting {- return &api.BackupSetting{- ID: raw.ID,-- UpdatedTs: raw.UpdatedTs,-- // Related fields- DatabaseID: raw.DatabaseID,-- // Domain specific fields- Enabled: raw.Enabled,- Hour: raw.Hour,- DayOfWeek: raw.DayOfWeek,- RetentionPeriodTs: raw.RetentionPeriodTs,- // HookURL is the callback url to be requested (using HTTP GET) after a successful backup.- HookURL: raw.HookURL,- }-}--// UpsertBackupSetting upserts an instance of backup setting.-func (s *Store) UpsertBackupSetting(ctx context.Context, upsert *api.BackupSettingUpsert) (*api.BackupSetting, error) {- backupSettingRaw, err := s.upsertBackupSettingRaw(ctx, upsert)- if err != nil {- return nil, errors.Wrapf(err, "failed to upsert backup setting with BackupSettingUpsert[%+v]", upsert)- }- return backupSettingRaw.toBackupSetting(), nil+// BackupSettingsMatchMessage is the message to find backup settings matching the conditions.+type BackupSettingsMatchMessage struct {+ Hour int+ DayOfWeek int}// FindBackupSettingsMatch finds a list of backup setting instances with match conditions.-func (s *Store) FindBackupSettingsMatch(ctx context.Context, match *api.BackupSettingsMatch) ([]*api.BackupSetting, error) {- backupSettingRawList, err := s.findBackupSettingsMatchImpl(ctx, match)+func (s *Store) FindBackupSettingsMatch(ctx context.Context, match *BackupSettingsMatchMessage) ([]*BackupSettingMessage, error) {+ backupSettingList, err := s.findBackupSettingsMatchImpl(ctx, match)if err != nil {return nil, errors.Wrapf(err, "failed to find matching backup setting list with BackupSettingsMatch[%+v]", match)}- var backupSettingList []*api.BackupSetting- for _, raw := range backupSettingRawList {- backupSettingList = append(backupSettingList, raw.toBackupSetting())- }- return backupSettingList, nil-}--// upsertBackupSettingRaw sets the backup settings for a database.-func (s *Store) upsertBackupSettingRaw(ctx context.Context, upsert *api.BackupSettingUpsert) (*backupSettingRaw, error) {- if err := s.validateBackupSettingUpsert(ctx, upsert); err != nil {- return nil, err- }-- tx, err := s.db.BeginTx(ctx, nil)- if err != nil {- return nil, err- }- defer tx.Rollback()-- backupRaw, err := s.upsertBackupSettingImpl(ctx, tx, upsert)- if err != nil {- return nil, err- }-- if err := tx.Commit(); err != nil {- return nil, err- }-- return backupRaw, nil-}--func (s *Store) validateBackupSettingUpsert(ctx context.Context, upsert *api.BackupSettingUpsert) error {- backupPlanPolicy, err := s.GetBackupPlanPolicyByEnvID(ctx, upsert.EnvironmentID)- if err != nil {- return err- }- // Backup plan policy check for backup setting mutation.- if backupPlanPolicy.Schedule != api.BackupPlanPolicyScheduleUnset {- if !upsert.Enabled {- return &common.Error{Code: common.Invalid, Err: errors.Errorf("backup setting should not be disabled for backup plan policy schedule %q", backupPlanPolicy.Schedule)}- }- switch backupPlanPolicy.Schedule {- case api.BackupPlanPolicyScheduleDaily:- if upsert.DayOfWeek != -1 {- return &common.Error{Code: common.Invalid, Err: errors.Errorf("backup setting DayOfWeek should be unset for backup plan policy schedule %q", backupPlanPolicy.Schedule)}- }- case api.BackupPlanPolicyScheduleWeekly:- if upsert.DayOfWeek == -1 {- return &common.Error{Code: common.Invalid, Err: errors.Errorf("backup setting DayOfWeek should be set for backup plan policy schedule %q", backupPlanPolicy.Schedule)}- }- }- }- return nil-}-// upsertBackupSettingImpl updates an existing backup setting.-func (*Store) upsertBackupSettingImpl(ctx context.Context, tx *Tx, upsert *api.BackupSettingUpsert) (*backupSettingRaw, error) {- // Upsert row into backup_setting.- query := `- INSERT INTO backup_setting (- creator_id,- updater_id,- database_id,- enabled,- hour,- day_of_week,- retention_period_ts,- hook_url- )- VALUES ($1, $2, $3, $4, $5, $6, $7, $8)- ON CONFLICT(database_id) DO UPDATE SET- enabled = EXCLUDED.enabled,- hour = EXCLUDED.hour,- day_of_week = EXCLUDED.day_of_week,- retention_period_ts = EXCLUDED.retention_period_ts,- hook_url = EXCLUDED.hook_url- RETURNING id, updated_ts, database_id, enabled, hour, day_of_week, retention_period_ts, hook_url- `- var backupSettingRaw backupSettingRaw- if err := tx.QueryRowContext(ctx, query,- upsert.UpdaterID,- upsert.UpdaterID,- upsert.DatabaseID,- upsert.Enabled,- upsert.Hour,- upsert.DayOfWeek,- upsert.RetentionPeriodTs,- upsert.HookURL,- ).Scan(- &backupSettingRaw.ID,- &backupSettingRaw.UpdatedTs,- &backupSettingRaw.DatabaseID,- &backupSettingRaw.Enabled,- &backupSettingRaw.Hour,- &backupSettingRaw.DayOfWeek,- &backupSettingRaw.RetentionPeriodTs,- &backupSettingRaw.HookURL,- ); err != nil {- if err == sql.ErrNoRows {- return nil, common.FormatDBErrorEmptyRowWithQuery(query)- }- return nil, err- }- return &backupSettingRaw, nil+ return backupSettingList, nil}// findBackupSettingsMatchImpl retrieves a list of backup settings based on match condition.-func (s *Store) findBackupSettingsMatchImpl(ctx context.Context, match *api.BackupSettingsMatch) ([]*backupSettingRaw, error) {+func (s *Store) findBackupSettingsMatchImpl(ctx context.Context, match *BackupSettingsMatchMessage) ([]*BackupSettingMessage, error) {tx, err := s.db.BeginTx(ctx, nil)if err != nil {return nil, err@@ -185,8 +40,6 @@ func (s *Store) findBackupSettingsMatchImpl(ctx context.Context, match *api.Backrows, err := tx.QueryContext(ctx, `SELECT- id,- updated_ts,database_id,enabled,hour,@@ -211,30 +64,28 @@ func (s *Store) findBackupSettingsMatchImpl(ctx context.Context, match *api.Back}defer rows.Close()- // Iterate over result set and deserialize rows into backupSettingRawList.- var backupSettingRawList []*backupSettingRaw+ // Iterate over result set and deserialize rows into backupSettingList.+ var backupSettingList []*BackupSettingMessagefor rows.Next() {- var backupSettingRaw backupSettingRaw+ var backupSetting BackupSettingMessageif err := rows.Scan(- &backupSettingRaw.ID,- &backupSettingRaw.UpdatedTs,- &backupSettingRaw.DatabaseID,- &backupSettingRaw.Enabled,- &backupSettingRaw.Hour,- &backupSettingRaw.DayOfWeek,- &backupSettingRaw.RetentionPeriodTs,- &backupSettingRaw.HookURL,+ &backupSetting.DatabaseUID,+ &backupSetting.Enabled,+ &backupSetting.HourOfDay,+ &backupSetting.DayOfWeek,+ &backupSetting.RetentionPeriodTs,+ &backupSetting.HookURL,); err != nil {return nil, err}- backupSettingRawList = append(backupSettingRawList, &backupSettingRaw)+ backupSettingList = append(backupSettingList, &backupSetting)}if err := rows.Err(); err != nil {return nil, err}- return backupSettingRawList, nil+ return backupSettingList, nil}// BackupSettingMessage is the message for backup setting.@@ -257,20 +108,6 @@ type BackupSettingMessage struct {HookURL string}-// ToAPIBackupSetting converts BackupSettingMessage to legacy api BackupSetting.-func (b *BackupSettingMessage) ToAPIBackupSetting() *api.BackupSetting {- return &api.BackupSetting{- ID: b.ID,- DatabaseID: b.DatabaseUID,- UpdatedTs: b.UpdatedTs,- Enabled: b.Enabled,- Hour: b.HourOfDay,- DayOfWeek: b.DayOfWeek,- RetentionPeriodTs: b.RetentionPeriodTs,- HookURL: b.HookURL,- }-}-// FindBackupSettingMessage is the message for finding backup setting.type FindBackupSettingMessage struct {// DatabaseUID is the UID of database.diff --git a/backend/tests/backup_restore_test.go b/backend/tests/backup_restore_test.goindex 18e2e780ae..2264356cea 100644--- a/backend/tests/backup_restore_test.go+++ b/backend/tests/backup_restore_test.go@@ -482,7 +482,7 @@ func setUpForPITRTest(ctx context.Context, t *testing.T, ctl *controller) (contedatabaseUID, err := strconv.Atoi(database.Uid)a.NoError(err)- err = ctl.disableAutomaticBackup(databaseUID)+ err = ctl.disableAutomaticBackup(ctx, database.Name)a.NoError(err)mysqlDB := initPITRDB(t, databaseName, mysqlPort)diff --git a/backend/tests/database.go b/backend/tests/database.goindex 07cbd240d9..01e46c7f1c 100644--- a/backend/tests/database.go+++ b/backend/tests/database.go@@ -1,7 +1,6 @@package testsimport (- "bytes""context""encoding/json""fmt"@@ -13,6 +12,7 @@ import ("github.com/google/jsonapi""github.com/pkg/errors""go.uber.org/zap"+ "google.golang.org/protobuf/types/known/durationpb""github.com/bytebase/bytebase/backend/common/log"api "github.com/bytebase/bytebase/backend/legacyapi"@@ -217,19 +217,17 @@ func marshalLabels(labelMap map[string]string, environmentID string) (string, er}// disableAutomaticBackup disables the automatic backup of a database.-func (ctl *controller) disableAutomaticBackup(databaseID int) error {- backupSetting := api.BackupSettingUpsert{- DatabaseID: databaseID,- Enabled: false,- }- buf := new(bytes.Buffer)- if err := jsonapi.MarshalPayload(buf, &backupSetting); err != nil {- return errors.Wrap(err, "failed to marshal backupSetting")- }-- if _, err := ctl.patch(fmt.Sprintf("/database/%d/backup-setting", databaseID), buf); err != nil {+func (ctl *controller) disableAutomaticBackup(ctx context.Context, databaseName string) error {+ if _, err := ctl.databaseServiceClient.UpdateBackupSetting(ctx, &v1pb.UpdateBackupSettingRequest{+ Setting: &v1pb.BackupSetting{+ Name: fmt.Sprintf("%s/backupSetting", databaseName),+ CronSchedule: "",+ BackupRetainDuration: durationpb.New(time.Duration(7*24*60*60) * time.Second),+ },+ }); err != nil {return err}+return nil}