Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

FEATURE (backups): Include workspace name in notification about success or fail

Rostislav Dugin0bc93389cc3d
diff --git a/backend/internal/features/backups/backups/service.go b/backend/internal/features/backups/backups/service.go
index 11f0ab27..29d7318b 100644
--- a/backend/internal/features/backups/backups/service.go
+++ b/backend/internal/features/backups/backups/service.go
@@ -366,6 +366,11 @@ func (s *BackupService) SendBackupNotification(
return
}
+ workspace, err := s.workspaceService.GetWorkspaceByID(*database.WorkspaceID)
+ if err != nil {
+ return
+ }
+
for _, notifier := range database.Notifiers {
if !slices.Contains(
backupConfig.SendNotificationsOn,
@@ -377,9 +382,17 @@ func (s *BackupService) SendBackupNotification(
title := ""
switch notificationType {
case backups_config.NotificationBackupFailed:
- title = fmt.Sprintf("❌ Backup failed for database \"%s\"", database.Name)
+ title = fmt.Sprintf(
+ "❌ Backup failed for database \"%s\" (workspace \"%s\")",
+ database.Name,
+ workspace.Name,
+ )
case backups_config.NotificationBackupSuccess:
- title = fmt.Sprintf("✅ Backup completed for database \"%s\"", database.Name)
+ title = fmt.Sprintf(
+ "✅ Backup completed for database \"%s\" (workspace \"%s\")",
+ database.Name,
+ workspace.Name,
+ )
}
message := ""
diff --git a/backend/internal/features/backups/backups/service_test.go b/backend/internal/features/backups/backups/service_test.go
index f9ef3793..12df548d 100644
--- a/backend/internal/features/backups/backups/service_test.go
+++ b/backend/internal/features/backups/backups/service_test.go
@@ -9,6 +9,7 @@ import (
"postgresus-backend/internal/features/storages"
users_enums "postgresus-backend/internal/features/users/enums"
users_testing "postgresus-backend/internal/features/users/testing"
+ workspaces_services "postgresus-backend/internal/features/workspaces/services"
workspaces_testing "postgresus-backend/internal/features/workspaces/testing"
"postgresus-backend/internal/util/logger"
"strings"
@@ -55,7 +56,7 @@ func Test_BackupExecuted_NotificationSent(t *testing.T) {
&CreateFailedBackupUsecase{},
logger.GetLogger(),
[]BackupRemoveListener{},
- nil, // workspaceService
+ workspaces_services.GetWorkspaceService(),
nil, // auditLogService
NewBackupContextManager(),
}
@@ -101,7 +102,7 @@ func Test_BackupExecuted_NotificationSent(t *testing.T) {
&CreateSuccessBackupUsecase{},
logger.GetLogger(),
[]BackupRemoveListener{},
- nil, // workspaceService
+ workspaces_services.GetWorkspaceService(),
nil, // auditLogService
NewBackupContextManager(),
}
@@ -124,7 +125,7 @@ func Test_BackupExecuted_NotificationSent(t *testing.T) {
&CreateSuccessBackupUsecase{},
logger.GetLogger(),
[]BackupRemoveListener{},
- nil, // workspaceService
+ workspaces_services.GetWorkspaceService(),
nil, // auditLogService
NewBackupContextManager(),
}
diff --git a/backend/internal/features/workspaces/services/workspace_service.go b/backend/internal/features/workspaces/services/workspace_service.go
index 5afd8aa2..20fddd9e 100644
--- a/backend/internal/features/workspaces/services/workspace_service.go
+++ b/backend/internal/features/workspaces/services/workspace_service.go
@@ -309,7 +309,7 @@ func (s *WorkspaceService) GetAllWorkspaces() ([]*workspaces_models.Workspace, e
return s.workspaceRepository.GetAllWorkspaces()
}
-func (s *WorkspaceService) GetWorkspaceByIDInternal(
+func (s *WorkspaceService) GetWorkspaceByID(
workspaceID uuid.UUID,
) (*workspaces_models.Workspace, error) {
return s.workspaceRepository.GetWorkspaceByID(workspaceID)