Add local support for soft deleting execution backups

This commit is contained in:
Luis Eduardo Jeréz Girón
2024-08-03 22:39:58 -06:00
parent 8853b6f13e
commit 2a600f705b
2 changed files with 25 additions and 7 deletions

View File

@@ -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)
}

View File

@@ -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