Skip to content

Commit 1f17e21

Browse files
committed
fix: resolve type errors in auto-delete and protection features
- Fix LocalTime conversion in base.go and entity_storage.go (use .Time field) - Fix CLI actions.go to use pointer for Protected field - Fix routes.go to use updatedClone.Protected for telemetry event - Add thinclones import and DestroyOptions parameter in auto_delete.go - Fix clone_test.go to handle Protected pointer properly
1 parent 232c43a commit 1f17e21

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

engine/cmd/cli/commands/clone/actions.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ func update(cliCtx *cli.Context) error {
184184
return err
185185
}
186186

187+
protected := cliCtx.Bool("protected")
187188
updateRequest := types.CloneUpdateRequest{
188-
Protected: cliCtx.Bool("protected"),
189+
Protected: &protected,
189190
}
190191

191192
cloneID := cliCtx.Args().First()

engine/internal/cloning/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ func (c *Base) destroyScheduledClones(ctx context.Context) {
852852
continue
853853
}
854854

855-
if time.Time(*clone.DeleteAt).After(now) {
855+
if clone.DeleteAt.Time.After(now) {
856856
continue
857857
}
858858

engine/internal/cloning/entity_storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func (es *EntityStorage) GetExpiredBranches() []*BranchMeta {
287287

288288
for _, meta := range es.branches {
289289
if meta.DeleteAt != nil && meta.AutoDeleteMode != models.AutoDeleteOff {
290-
if time.Time(*meta.DeleteAt).Before(now) {
290+
if meta.DeleteAt.Time.Before(now) {
291291
expired = append(expired, meta)
292292
}
293293
}
@@ -306,7 +306,7 @@ func (es *EntityStorage) GetExpiredSnapshots() []*SnapshotMeta {
306306

307307
for _, meta := range es.snapshots {
308308
if meta.DeleteAt != nil && meta.AutoDeleteMode != models.AutoDeleteOff {
309-
if time.Time(*meta.DeleteAt).Before(now) {
309+
if meta.DeleteAt.Time.Before(now) {
310310
expired = append(expired, meta)
311311
}
312312
}

engine/internal/srv/auto_delete.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"gitlab.com/postgres-ai/database-lab/v3/internal/cloning"
1414
"gitlab.com/postgres-ai/database-lab/v3/internal/provision/pool"
15+
"gitlab.com/postgres-ai/database-lab/v3/internal/provision/thinclones"
1516
"gitlab.com/postgres-ai/database-lab/v3/internal/webhooks"
1617
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
1718
"gitlab.com/postgres-ai/database-lab/v3/pkg/models"
@@ -224,7 +225,7 @@ func (s *Server) processExpiredSnapshots(ctx context.Context) {
224225

225226
log.Msg(fmt.Sprintf("Scheduled snapshot %q is going to be removed (deleteAt: %s)", meta.ID, meta.DeleteAt.Time.Format(time.RFC3339)))
226227

227-
if err := fsm.DestroySnapshot(meta.ID); err != nil {
228+
if err := fsm.DestroySnapshot(meta.ID, thinclones.DestroyOptions{}); err != nil {
228229
log.Errf("failed to destroy scheduled snapshot %q: %v", meta.ID, err)
229230
continue
230231
}
@@ -295,7 +296,7 @@ func (s *Server) forceDeleteSnapshot(ctx context.Context, fsm pool.FSManager, sn
295296
}
296297
}
297298

298-
if err := fsm.DestroySnapshot(snapshotID); err != nil {
299+
if err := fsm.DestroySnapshot(snapshotID, thinclones.DestroyOptions{}); err != nil {
299300
return fmt.Errorf("failed to destroy snapshot: %w", err)
300301
}
301302

engine/internal/srv/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ func (s *Server) patchClone(w http.ResponseWriter, r *http.Request) {
822822

823823
s.tm.SendEvent(context.Background(), telemetry.CloneUpdatedEvent, telemetry.CloneUpdated{
824824
ID: util.HashID(cloneID),
825-
Protected: patchClone.Protected,
825+
Protected: updatedClone.Protected,
826826
})
827827

828828
if err := api.WriteJSON(w, http.StatusOK, updatedClone); err != nil {

engine/pkg/client/dblabapi/clone_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ func TestClientUpdateClone(t *testing.T) {
366366
err = json.Unmarshal(requestBody, &updateRequest)
367367
require.NoError(t, err)
368368

369-
cloneModel.Protected = updateRequest.Protected
369+
if updateRequest.Protected != nil {
370+
cloneModel.Protected = *updateRequest.Protected
371+
}
370372

371373
// Prepare response.
372374
responseBody, err := json.Marshal(cloneModel)
@@ -388,8 +390,9 @@ func TestClientUpdateClone(t *testing.T) {
388390
c.client = mockClient
389391

390392
// Send a request.
393+
protectedFalse := false
391394
newClone, err := c.UpdateClone(context.Background(), cloneModel.ID, types.CloneUpdateRequest{
392-
Protected: false,
395+
Protected: &protectedFalse,
393396
})
394397
require.NoError(t, err)
395398

0 commit comments

Comments
 (0)