Skip to content

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

FIX (extensions): Exclude extensions comments as well

Rostislav Dugin31723966681a
diff --git a/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go b/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go
index 968c31cd..392373d1 100644
--- a/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go
+++ b/backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go
@@ -599,21 +599,21 @@ func (uc *RestorePostgresqlBackupUsecase) generateFilteredTocList(
return "", fmt.Errorf("failed to generate TOC list: %w", err)
}
- // Filter out EXTENSION lines
+ // Filter out EXTENSION-related lines (both CREATE EXTENSION and COMMENT ON EXTENSION)
var filteredLines []string
- for _, line := range strings.Split(string(tocOutput), "\n") {
- // Skip lines that contain EXTENSION (but not COMMENT ON EXTENSION)
- // TOC format: "123; 1234 12345 EXTENSION - extension_name owner"
+ for line := range strings.SplitSeq(string(tocOutput), "\n") {
trimmedLine := strings.TrimSpace(line)
if trimmedLine == "" {
continue
}
- // Check if this is an EXTENSION entry (not a comment about extension)
- // Extension lines look like: "3420; 0 0 EXTENSION - uuid-ossp"
- if strings.Contains(trimmedLine, " EXTENSION ") &&
- !strings.Contains(strings.ToUpper(trimmedLine), "COMMENT") {
- uc.logger.Info("Excluding extension from restore", "tocLine", trimmedLine)
+ upperLine := strings.ToUpper(trimmedLine)
+
+ // Skip lines that contain " EXTENSION " - this catches both:
+ // - CREATE EXTENSION entries: "3420; 0 0 EXTENSION - uuid-ossp"
+ // - COMMENT ON EXTENSION entries: "3462; 0 0 COMMENT - EXTENSION "uuid-ossp""
+ if strings.Contains(upperLine, " EXTENSION ") {
+ uc.logger.Info("Excluding extension-related entry from restore", "tocLine", trimmedLine)
continue
}
diff --git a/backend/internal/features/tests/postgresql_backup_restore_test.go b/backend/internal/features/tests/postgresql_backup_restore_test.go
index a4930bc4..20d28aad 100644
--- a/backend/internal/features/tests/postgresql_backup_restore_test.go
+++ b/backend/internal/features/tests/postgresql_backup_restore_test.go
@@ -548,10 +548,12 @@ func testBackupRestoreWithExcludeExtensionsForVersion(t *testing.T, pgVersion st
assert.NoError(t, err)
defer container.DB.Close()
- // Create table with uuid-ossp extension
+ // Create table with uuid-ossp extension and add a comment on the extension
+ // The comment is important to test that COMMENT ON EXTENSION statements are also excluded
_, err = container.DB.Exec(`
DROP EXTENSION IF EXISTS "uuid-ossp" CASCADE;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
+ COMMENT ON EXTENSION "uuid-ossp" IS 'Test comment on uuid-ossp extension';
DROP TABLE IF EXISTS test_extension_data;
CREATE TABLE test_extension_data (