From 2a600f705b6b1a7162b88cd746ef450b89a9a575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Eduardo=20Jer=C3=A9z=20Gir=C3=B3n?= Date: Sat, 3 Aug 2024 22:39:58 -0600 Subject: [PATCH] Add local support for soft deleting execution backups --- .../executions/soft_delete_execution.go | 13 ++++++++++--- .../executions/soft_delete_execution.sql | 19 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/internal/service/executions/soft_delete_execution.go b/internal/service/executions/soft_delete_execution.go index f7f0be2..742d85c 100644 --- a/internal/service/executions/soft_delete_execution.go +++ b/internal/service/executions/soft_delete_execution.go @@ -25,16 +25,23 @@ func (s *Service) SoftDeleteExecution( return err } - if execution.ExecutionPath.Valid { + if execution.ExecutionPath.Valid && !execution.BackupIsLocal { err := s.ints.StorageClient.S3Delete( execution.DecryptedDestinationAccessKey, execution.DecryptedDestinationSecretKey, - execution.DestinationRegion, execution.DestinationEndpoint, - execution.DestinationBucketName, execution.ExecutionPath.String, + execution.DestinationRegion.String, execution.DestinationEndpoint.String, + execution.DestinationBucketName.String, execution.ExecutionPath.String, ) if err != nil { return err } } + if execution.ExecutionPath.Valid && execution.BackupIsLocal { + err := s.ints.StorageClient.LocalDelete(execution.ExecutionPath.String) + if err != nil { + return err + } + } + return s.dbgen.ExecutionsServiceSoftDeleteExecution(ctx, executionID) } diff --git a/internal/service/executions/soft_delete_execution.sql b/internal/service/executions/soft_delete_execution.sql index 94d5a1d..888aa15 100644 --- a/internal/service/executions/soft_delete_execution.sql +++ b/internal/service/executions/soft_delete_execution.sql @@ -4,15 +4,26 @@ SELECT executions.path as execution_path, backups.id as backup_id, + backups.is_local as backup_is_local, destinations.bucket_name as destination_bucket_name, destinations.region as destination_region, destinations.endpoint as destination_endpoint, - pgp_sym_decrypt(destinations.access_key, @encryption_key) AS decrypted_destination_access_key, - pgp_sym_decrypt(destinations.secret_key, @encryption_key) AS decrypted_destination_secret_key + ( + CASE WHEN destinations.access_key IS NOT NULL + THEN pgp_sym_decrypt(destinations.access_key, sqlc.arg('encryption_key')::TEXT) + ELSE '' + END + ) AS decrypted_destination_access_key, + ( + CASE WHEN destinations.secret_key IS NOT NULL + THEN pgp_sym_decrypt(destinations.secret_key, sqlc.arg('encryption_key')::TEXT) + ELSE '' + END + ) AS decrypted_destination_secret_key FROM executions -JOIN backups ON backups.id = executions.backup_id -JOIN destinations ON destinations.id = backups.destination_id +INNER JOIN backups ON backups.id = executions.backup_id +LEFT JOIN destinations ON destinations.id = backups.destination_id WHERE executions.id = @execution_id; -- name: ExecutionsServiceSoftDeleteExecution :exec