Skip to content

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

FIX (databases): Trim and split pasted exclude tables lists so they reach dump args

Rostislav Dugin54b19eb3fafa
diff --git a/CLAUDE.md b/CLAUDE.md
index 1de75edc..d72b476c 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -17,6 +17,8 @@ This root file holds the engineering philosophy that applies everywhere.
Work happens inside the repo's [Dev Container](.devcontainer/devcontainer.json). The container ships Go, Node.js + pnpm, Docker-in-Docker, linters and matching VS Code extensions, so the toolchain is identical for every contributor. Ports `4005` (backend) and `5173` (Vite) are forwarded automatically. Don't install or rely on host-level SDKs — run `make`, `pnpm` and `docker` commands from inside the container.
+Running the backend suite host-native is supported on Fedora via `make test-fedora`, which shims the Debian soname the bundled `assets/tools` clients expect. Any other host distro is on its own — the container stays the reference environment. Also project sometimes is run in different worktrees, in this case it is needed to copy .env.example -> .env and `pnpm install` to run tests
+
---
## Language in code
diff --git a/backend/Makefile b/backend/Makefile
index 1161ae12..18f46ddb 100644
--- a/backend/Makefile
+++ b/backend/Makefile
@@ -15,6 +15,19 @@ test: clean-testcontainers pull-testcontainers
done
TESTCONTAINERS_RYUK_DISABLED=true TEST_PARALLEL_WORKERS=$(TEST_PARALLEL_WORKERS) go test -p=$(TEST_PARALLEL_WORKERS) -count=1 -failfast -timeout 15m ./internal/...
+LIBEDIT_SHIM_DIR ?= $(HOME)/.local/lib/databasus-compat
+
+# The bundled DB clients in assets/tools are Debian-built and link libedit.so.2,
+# a soname Debian patches in downstream; Fedora ships the upstream libedit.so.0.
+# The ABI is identical, so renaming via symlink is safe.
+test-fedora:
+ @libedit=/usr/lib64/libedit.so.0; \
+ [ -e "$$libedit" ] || libedit=$$(ldconfig -p | awk '/libedit\.so\.0 / {print $$NF; exit}'); \
+ if [ -z "$$libedit" ]; then echo "libedit.so.0 not found — install it with: sudo dnf install libedit"; exit 1; fi; \
+ mkdir -p $(LIBEDIT_SHIM_DIR); \
+ ln -sf "$$libedit" $(LIBEDIT_SHIM_DIR)/libedit.so.2
+ @LD_LIBRARY_PATH="$(LIBEDIT_SHIM_DIR)$${LD_LIBRARY_PATH:+:$$LD_LIBRARY_PATH}" $(MAKE) test
+
clean-testcontainers:
@ids=$$(docker ps -aq --filter "label=org.testcontainers"); \
if [ -n "$$ids" ]; then docker rm -f $$ids; else echo "no leftover testcontainers"; fi
diff --git a/backend/internal/features/backups/backups/usecases/logical/mariadb/create_backup_uc.go b/backend/internal/features/backups/backups/usecases/logical/mariadb/create_backup_uc.go
index d2251e81..7ae51208 100644
--- a/backend/internal/features/backups/backups/usecases/logical/mariadb/create_backup_uc.go
+++ b/backend/internal/features/backups/backups/usecases/logical/mariadb/create_backup_uc.go
@@ -27,6 +27,7 @@ import (
"databasus-backend/internal/features/storages"
"databasus-backend/internal/util/encryption"
io_utils "databasus-backend/internal/util/io"
+ "databasus-backend/internal/util/namelist"
"databasus-backend/internal/util/tools"
)
@@ -145,8 +146,8 @@ func (uc *CreateMariadbBackupUsecase) buildMariadbDumpArgs(
}
if mdb.Database != nil && *mdb.Database != "" {
- for _, table := range mdb.ExcludeTables {
- args = append(args, "--ignore-table="+*mdb.Database+"."+table)
+ for _, excludedTable := range namelist.NormalizeUniqueNames(mdb.ExcludeTables) {
+ args = append(args, "--ignore-table="+*mdb.Database+"."+excludedTable)
}
}
diff --git a/backend/internal/features/backups/backups/usecases/logical/mariadb/create_backup_uc_test.go b/backend/internal/features/backups/backups/usecases/logical/mariadb/create_backup_uc_test.go
index 30feb5ea..9b10de56 100644
--- a/backend/internal/features/backups/backups/usecases/logical/mariadb/create_backup_uc_test.go
+++ b/backend/internal/features/backups/backups/usecases/logical/mariadb/create_backup_uc_test.go
@@ -2,6 +2,7 @@ package usecases_logical_mariadb
import (
"slices"
+ "strings"
"testing"
mariadbtypes "databasus-backend/internal/features/databases/databases/mariadb"
@@ -35,3 +36,70 @@ func Test_BuildMariadbDumpArgs_WhenExtendedInsertEnabled_OmitsSkipExtendedInsert
t.Fatalf("expected no --skip-extended-insert when extended inserts are enabled, got %v", args)
}
}
+
+func Test_BuildMariadbDumpArgs_WithExcludedTables_AddsQualifiedIgnoreTableArgs(t *testing.T) {
+ uc := &CreateMariadbBackupUsecase{}
+ databaseName := "oa_db"
+ database := &mariadbtypes.MariadbDatabase{
+ Version: tools.MariadbVersion114,
+ Database: &databaseName,
+ ExcludeTables: []string{"personnel_access_control_event", "personnel_real_time"},
+ }
+
+ args := uc.buildMariadbDumpArgs(database)
+
+ if !slices.Contains(args, "--ignore-table=oa_db.personnel_access_control_event") ||
+ !slices.Contains(args, "--ignore-table=oa_db.personnel_real_time") {
+ t.Fatalf("expected an --ignore-table arg per excluded table, got %v", args)
+ }
+}
+
+func Test_BuildMariadbDumpArgs_WhenExcludedTablesArePastedMultiline_TrimsAndSplitsThem(t *testing.T) {
+ uc := &CreateMariadbBackupUsecase{}
+ databaseName := "oa_db"
+ database := &mariadbtypes.MariadbDatabase{
+ Version: tools.MariadbVersion114,
+ Database: &databaseName,
+ ExcludeTables: []string{
+ "personnel_access_control_event",
+ "\npersonnel_real_time",
+ " ",
+ "ext_alarm_message,\nmonitor_toxic_gas",
+ },
+ }
+
+ args := uc.buildMariadbDumpArgs(database)
+
+ ignoredTableArgs := []string{
+ "--ignore-table=oa_db.personnel_access_control_event",
+ "--ignore-table=oa_db.personnel_real_time",
+ "--ignore-table=oa_db.ext_alarm_message",
+ "--ignore-table=oa_db.monitor_toxic_gas",
+ }
+ for _, ignoredTableArg := range ignoredTableArgs {
+ if !slices.Contains(args, ignoredTableArg) {
+ t.Fatalf("expected %s, got %v", ignoredTableArg, args)
+ }
+ }
+
+ if slices.Contains(args, "--ignore-table=oa_db.") {
+ t.Fatalf("expected blank excluded tables to be dropped, got %v", args)
+ }
+}
+
+func Test_BuildMariadbDumpArgs_WithoutExcludedTables_OmitsIgnoreTableArgs(t *testing.T) {
+ uc := &CreateMariadbBackupUsecase{}
+ databaseName := "oa_db"
+ database := &mariadbtypes.MariadbDatabase{
+ Version: tools.MariadbVersion114,
+ Database: &databaseName,
+ }
+
+ args := uc.buildMariadbDumpArgs(database)
+
+ for _, arg := range args {
+ if strings.HasPrefix(arg, "--ignore-table=") {
+ t.Fatalf("expected no --ignore-table args, got %v", args)
+ }
+ }
+}
diff --git a/backend/internal/features/backups/backups/usecases/logical/mongodb/create_backup_uc.go b/backend/internal/features/backups/backups/usecases/logical/mongodb/create_backup_uc.go
index 9ced8169..51c9d6f4 100644
--- a/backend/internal/features/backups/backups/usecases/logical/mongodb/create_backup_uc.go
+++ b/backend/internal/features/backups/backups/usecases/logical/mongodb/create_backup_uc.go
@@ -23,6 +23,7 @@ import (
encryption_secrets "databasus-backend/internal/features/encryption/secrets"
"databasus-backend/internal/features/storages"
"databasus-backend/internal/util/encryption"
+ "databasus-backend/internal/util/namelist"
"databasus-backend/internal/util/tools"
)
@@ -111,8 +112,8 @@ func (uc *CreateMongodbBackupUsecase) buildMongodumpArgs(
"--gzip",
}
- for _, collection := range mdb.ExcludeCollections {
- args = append(args, "--excludeCollection="+collection)
+ for _, excludedCollection := range namelist.NormalizeUniqueNames(mdb.ExcludeCollections) {
+ args = append(args, "--excludeCollection="+excludedCollection)
}
// Use numParallelCollections based on CPU count
diff --git a/backend/internal/features/backups/backups/usecases/logical/mysql/create_backup_uc.go b/backend/internal/features/backups/backups/usecases/logical/mysql/create_backup_uc.go
index d7f961d8..4147cba4 100644
--- a/backend/internal/features/backups/backups/usecases/logical/mysql/create_backup_uc.go
+++ b/backend/internal/features/backups/backups/usecases/logical/mysql/create_backup_uc.go
@@ -27,6 +27,7 @@ import (
"databasus-backend/internal/features/storages"
"databasus-backend/internal/util/encryption"
io_utils "databasus-backend/internal/util/io"
+ "databasus-backend/internal/util/namelist"
"databasus-backend/internal/util/tools"
)
@@ -143,8 +144,8 @@ func (uc *CreateMysqlBackupUsecase) buildMysqldumpArgs(my *mysqltypes.MysqlDatab
}
if my.Database != nil && *my.Database != "" {
- for _, table := range my.ExcludeTables {
- args = append(args, "--ignore-table="+*my.Database+"."+table)
+ for _, excludedTable := range namelist.NormalizeUniqueNames(my.ExcludeTables) {
+ args = append(args, "--ignore-table="+*my.Database+"."+excludedTable)
}
}
diff --git a/backend/internal/features/backups/backups/usecases/logical/mysql/create_backup_uc_test.go b/backend/internal/features/backups/backups/usecases/logical/mysql/create_backup_uc_test.go
index 2f745060..c56cc629 100644
--- a/backend/internal/features/backups/backups/usecases/logical/mysql/create_backup_uc_test.go
+++ b/backend/internal/features/backups/backups/usecases/logical/mysql/create_backup_uc_test.go
@@ -2,6 +2,7 @@ package usecases_logical_mysql
import (
"slices"
+ "strings"
"testing"
mysqltypes "databasus-backend/internal/features/databases/databases/mysql"
@@ -35,3 +36,70 @@ func Test_BuildMysqldumpArgs_WhenExtendedInsertEnabled_OmitsSkipExtendedInsert(t
t.Fatalf("expected no --skip-extended-insert when extended inserts are enabled, got %v", args)
}
}
+
+func Test_BuildMysqldumpArgs_WithExcludedTables_AddsQualifiedIgnoreTableArgs(t *testing.T) {
+ uc := &CreateMysqlBackupUsecase{}
+ databaseName := "oa_db"
+ database := &mysqltypes.MysqlDatabase{
+ Version: tools.MysqlVersion80,
+ Database: &databaseName,
+ ExcludeTables: []string{"personnel_access_control_event", "personnel_real_time"},
+ }
+
+ args := uc.buildMysqldumpArgs(database)
+
+ if !slices.Contains(args, "--ignore-table=oa_db.personnel_access_control_event") ||
+ !slices.Contains(args, "--ignore-table=oa_db.personnel_real_time") {
+ t.Fatalf("expected an --ignore-table arg per excluded table, got %v", args)
+ }
+}
+
+func Test_BuildMysqldumpArgs_WhenExcludedTablesArePastedMultiline_TrimsAndSplitsThem(t *testing.T) {
+ uc := &CreateMysqlBackupUsecase{}
+ databaseName := "oa_db"
+ database := &mysqltypes.MysqlDatabase{
+ Version: tools.MysqlVersion80,
+ Database: &databaseName,
+ ExcludeTables: []string{
+ "personnel_access_control_event",
+ "\npersonnel_real_time",
+ " ",
+ "ext_alarm_message,\nmonitor_toxic_gas",
+ },
+ }
+
+ args := uc.buildMysqldumpArgs(database)
+
+ ignoredTableArgs := []string{
+ "--ignore-table=oa_db.personnel_access_control_event",
+ "--ignore-table=oa_db.personnel_real_time",
+ "--ignore-table=oa_db.ext_alarm_message",
+ "--ignore-table=oa_db.monitor_toxic_gas",
+ }
+ for _, ignoredTableArg := range ignoredTableArgs {
+ if !slices.Contains(args, ignoredTableArg) {
+ t.Fatalf("expected %s, got %v", ignoredTableArg, args)
+ }
+ }
+
+ if slices.Contains(args, "--ignore-table=oa_db.") {
+ t.Fatalf("expected blank excluded tables to be dropped, got %v", args)
+ }
+}
+
+func Test_BuildMysqldumpArgs_WithoutExcludedTables_OmitsIgnoreTableArgs(t *testing.T) {
+ uc := &CreateMysqlBackupUsecase{}
+ databaseName := "oa_db"
+ database := &mysqltypes.MysqlDatabase{
+ Version: tools.MysqlVersion80,
+ Database: &databaseName,
+ }
+
+ args := uc.buildMysqldumpArgs(database)
+
+ for _, arg := range args {
+ if strings.HasPrefix(arg, "--ignore-table=") {
+ t.Fatalf("expected no --ignore-table args, got %v", args)
+ }
+ }
+}
diff --git a/backend/internal/features/backups/backups/usecases/logical/postgresql/create_backup_uc.go b/backend/internal/features/backups/backups/usecases/logical/postgresql/create_backup_uc.go
index e7eee778..95019077 100644
--- a/backend/internal/features/backups/backups/usecases/logical/postgresql/create_backup_uc.go
+++ b/backend/internal/features/backups/backups/usecases/logical/postgresql/create_backup_uc.go
@@ -26,6 +26,7 @@ import (
encryption_secrets "databasus-backend/internal/features/encryption/secrets"
"databasus-backend/internal/features/storages"
"databasus-backend/internal/util/encryption"
+ "databasus-backend/internal/util/namelist"
"databasus-backend/internal/util/tools"
)
@@ -366,12 +367,12 @@ func (uc *CreatePostgresqlBackupUsecase) buildPgDumpArgs(pg *pgtypes.PostgresqlL
"--verbose",
}
- for _, schema := range pg.IncludeSchemas {
- args = append(args, "-n", schema)
+ for _, includedSchema := range namelist.NormalizeUniqueNames(pg.IncludeSchemas) {
+ args = append(args, "-n", includedSchema)
}
- for _, table := range pg.ExcludeTables {
- args = append(args, "--exclude-table="+table)
+ for _, excludedTable := range namelist.NormalizeUniqueNames(pg.ExcludeTables) {
+ args = append(args, "--exclude-table="+excludedTable)
}
compressionArgs := uc.getCompressionArgs(pg.Version)
diff --git a/backend/internal/features/databases/controller_test.go b/backend/internal/features/databases/controller_test.go
index b2087e70..7c04f609 100644
--- a/backend/internal/features/databases/controller_test.go
+++ b/backend/internal/features/databases/controller_test.go
@@ -1182,6 +1182,51 @@ func Test_TestConnection_PermissionsEnforced(t *testing.T) {
}
}
+func Test_UpdateDatabase_WhenExcludeTablesArePastedMultiline_StoresTrimmedUniqueNames(t *testing.T) {
+ router := createTestRouter()
+ owner := users_testing.CreateTestUser(users_enums.UserRoleMember)
+ workspace := workspaces_testing.CreateTestWorkspace("Test Workspace", owner, router)
+ defer workspaces_testing.RemoveTestWorkspace(workspace, router)
+
+ database := createTestDatabaseViaAPI("Test Database", workspace.ID, owner.Token, router)
+ defer RemoveTestDatabase(database)
+
+ database.PostgresqlLogical.ExcludeTables = []string{"orders", "\npersonnel_real_time", " ", "orders"}
+ database.PostgresqlLogical.IncludeSchemas = []string{"public", "\treporting"}
+
+ var updatedDatabase Database
+ test_utils.MakePostRequestAndUnmarshal(
+ t,
+ router,
+ "/api/v1/databases/update",
+ "Bearer "+owner.Token,
+ database,
+ http.StatusOK,
+ &updatedDatabase,
+ )
+
+ var reloadedDatabase Database
+ test_utils.MakeGetRequestAndUnmarshal(
+ t,
+ router,
+ "/api/v1/databases/"+database.ID.String(),
+ "Bearer "+owner.Token,
+ http.StatusOK,
+ &reloadedDatabase,
+ )
+
+ assert.Equal(
+ t,
+ []string{"orders", "personnel_real_time"},
+ reloadedDatabase.PostgresqlLogical.ExcludeTables,
+ )
+ assert.Equal(
+ t,
+ []string{"public", "reporting"},
+ reloadedDatabase.PostgresqlLogical.IncludeSchemas,
+ )
+}
+
func createTestDatabaseViaAPI(
name string,
workspaceID uuid.UUID,
diff --git a/backend/internal/features/databases/databases/mariadb/model.go b/backend/internal/features/databases/databases/mariadb/model.go
index 2a17fc55..1de6c5ac 100644
--- a/backend/internal/features/databases/databases/mariadb/model.go
+++ b/backend/internal/features/databases/databases/mariadb/model.go
@@ -17,6 +17,7 @@ import (
"gorm.io/gorm"
"databasus-backend/internal/util/encryption"
+ "databasus-backend/internal/util/namelist"
"databasus-backend/internal/util/tools"
)
@@ -45,21 +46,13 @@ func (m *MariadbDatabase) TableName() string {
}
func (m *MariadbDatabase) BeforeSave(_ *gorm.DB) error {
- if len(m.ExcludeTables) > 0 {
- m.ExcludeTablesString = strings.Join(m.ExcludeTables, ",")
- } else {
- m.ExcludeTablesString = ""
- }
+ m.ExcludeTablesString = namelist.FormatUniqueNames(m.ExcludeTables)
return nil
}
func (m *MariadbDatabase) AfterFind(_ *gorm.DB) error {
- if m.ExcludeTablesString != "" {
- m.ExcludeTables = strings.Split(m.ExcludeTablesString, ",")
- } else {
- m.ExcludeTables = []string{}
- }
+ m.ExcludeTables = namelist.ParseUniqueNames(m.ExcludeTablesString)
return nil
}
diff --git a/backend/internal/features/databases/databases/mongodb/model.go b/backend/internal/features/databases/databases/mongodb/model.go
index 0336fac2..7cd65640 100644
--- a/backend/internal/features/databases/databases/mongodb/model.go
+++ b/backend/internal/features/databases/databases/mongodb/model.go
@@ -17,6 +17,7 @@ import (
"gorm.io/gorm"
"databasus-backend/internal/util/encryption"
+ "databasus-backend/internal/util/namelist"
"databasus-backend/internal/util/tools"
)
@@ -45,21 +46,13 @@ func (m *MongodbDatabase) TableName() string {
}
func (m *MongodbDatabase) BeforeSave(_ *gorm.DB) error {
- if len(m.ExcludeCollections) > 0 {
- m.ExcludeCollectionsString = strings.Join(m.ExcludeCollections, ",")
- } else {
- m.ExcludeCollectionsString = ""
- }
+ m.ExcludeCollectionsString = namelist.FormatUniqueNames(m.ExcludeCollections)
return nil
}
func (m *MongodbDatabase) AfterFind(_ *gorm.DB) error {
- if m.ExcludeCollectionsString != "" {
- m.ExcludeCollections = strings.Split(m.ExcludeCollectionsString, ",")
- } else {
- m.ExcludeCollections = []string{}
- }
+ m.ExcludeCollections = namelist.ParseUniqueNames(m.ExcludeCollectionsString)
return nil
}
diff --git a/backend/internal/features/databases/databases/mysql/model.go b/backend/internal/features/databases/databases/mysql/model.go
index 27e616f6..295f1cf8 100644
--- a/backend/internal/features/databases/databases/mysql/model.go
+++ b/backend/internal/features/databases/databases/mysql/model.go
@@ -17,6 +17,7 @@ import (
"gorm.io/gorm"
"databasus-backend/internal/util/encryption"
+ "databasus-backend/internal/util/namelist"
"databasus-backend/internal/util/tools"
)
@@ -43,21 +44,13 @@ func (m *MysqlDatabase) TableName() string {
}
func (m *MysqlDatabase) BeforeSave(_ *gorm.DB) error {
- if len(m.ExcludeTables) > 0 {
- m.ExcludeTablesString = strings.Join(m.ExcludeTables, ",")
- } else {
- m.ExcludeTablesString = ""
- }
+ m.ExcludeTablesString = namelist.FormatUniqueNames(m.ExcludeTables)
return nil
}
func (m *MysqlDatabase) AfterFind(_ *gorm.DB) error {
- if m.ExcludeTablesString != "" {
- m.ExcludeTables = strings.Split(m.ExcludeTablesString, ",")
- } else {
- m.ExcludeTables = []string{}
- }
+ m.ExcludeTables = namelist.ParseUniqueNames(m.ExcludeTablesString)
return nil
}
diff --git a/backend/internal/features/databases/databases/postgresql/logical/model.go b/backend/internal/features/databases/databases/postgresql/logical/model.go
index e0e9fd3f..855ea1ba 100644
--- a/backend/internal/features/databases/databases/postgresql/logical/model.go
+++ b/backend/internal/features/databases/databases/postgresql/logical/model.go
@@ -16,6 +16,7 @@ import (
postgresql_shared "databasus-backend/internal/features/databases/databases/postgresql/shared"
"databasus-backend/internal/util/encryption"
+ "databasus-backend/internal/util/namelist"
"databasus-backend/internal/util/tools"
)
@@ -57,33 +58,15 @@ func (p *PostgresqlLogicalDatabase) TableName() string {
}
func (p *PostgresqlLogicalDatabase) BeforeSave(_ *gorm.DB) error {
- if len(p.IncludeSchemas) > 0 {
- p.IncludeSchemasString = strings.Join(p.IncludeSchemas, ",")
- } else {
- p.IncludeSchemasString = ""
- }
-
- if len(p.ExcludeTables) > 0 {
- p.ExcludeTablesString = strings.Join(p.ExcludeTables, ",")
- } else {
- p.ExcludeTablesString = ""
- }
+ p.IncludeSchemasString = namelist.FormatUniqueNames(p.IncludeSchemas)
+ p.ExcludeTablesString = namelist.FormatUniqueNames(p.ExcludeTables)
return nil
}
func (p *PostgresqlLogicalDatabase) AfterFind(_ *gorm.DB) error {
- if p.IncludeSchemasString != "" {
- p.IncludeSchemas = strings.Split(p.IncludeSchemasString, ",")
- } else {
- p.IncludeSchemas = []string{}
- }
-
- if p.ExcludeTablesString != "" {
- p.ExcludeTables = strings.Split(p.ExcludeTablesString, ",")
- } else {
- p.ExcludeTables = []string{}
- }
+ p.IncludeSchemas = namelist.ParseUniqueNames(p.IncludeSchemasString)
+ p.ExcludeTables = namelist.ParseUniqueNames(p.ExcludeTablesString)
return nil
}
diff --git a/backend/internal/features/tests/logical/mariadb/backup_restore_test.go b/backend/internal/features/tests/logical/mariadb/backup_restore_test.go
index 17eb637b..a5c61837 100644
--- a/backend/internal/features/tests/logical/mariadb/backup_restore_test.go
+++ b/backend/internal/features/tests/logical/mariadb/backup_restore_test.go
@@ -721,7 +721,7 @@ func testMariadbBackupRestoreWithExcludeTablesForVersion(
user.Token,
)
- database.Mariadb.ExcludeTables = []string{"extra_table"}
+ database.Mariadb.ExcludeTables = []string{"\nextra_table"}
w := workspaces_testing.MakeAPIRequest(
router,
"POST",
diff --git a/backend/internal/features/tests/logical/mysql/backup_restore_test.go b/backend/internal/features/tests/logical/mysql/backup_restore_test.go
index 21fdcdbb..a92f29c7 100644
--- a/backend/internal/features/tests/logical/mysql/backup_restore_test.go
+++ b/backend/internal/features/tests/logical/mysql/backup_restore_test.go
@@ -446,7 +446,7 @@ func testMysqlBackupRestoreWithExcludeTablesForVersion(
user.Token,
)
- database.Mysql.ExcludeTables = []string{"extra_table"}
+ database.Mysql.ExcludeTables = []string{"\nextra_table"}
w := workspaces_testing.MakeAPIRequest(
router,
"POST",
diff --git a/backend/internal/util/namelist/namelist.go b/backend/internal/util/namelist/namelist.go
new file mode 100644
index 00000000..d6a2a957
--- /dev/null
+++ b/backend/internal/util/namelist/namelist.go
@@ -0,0 +1,57 @@
+// Package namelist normalizes user-supplied lists of database object names.
+//
+// The UI collects these lists with an AntD tags input that splits pasted text on its
+// token separators without trimming, so a list pasted across several lines reaches us
+// with leading newlines glued to every entry but the first. Such an entry silently
+// matches nothing in mysqldump / pg_dump / mongodump, so the object it names ends up in
+// the backup anyway (issue #690).
+package namelist
+
+import (
+ "strings"
+)
+
+func NormalizeUniqueNames(names []string) []string {
+ normalizedNames := make([]string, 0, len(names))
+ seenNames := make(map[string]struct{}, len(names))
+
+ for _, name := range names {
+ for _, splitName := range splitOnSeparators(name) {
+ if _, isSeen := seenNames[splitName]; isSeen {
+ continue
+ }
+
+ seenNames[splitName] = struct{}{}
+ normalizedNames = append(normalizedNames, splitName)
+ }
+ }
+
+ return normalizedNames
+}
+
+func ParseUniqueNames(rawNames string) []string {
+ return NormalizeUniqueNames([]string{rawNames})
+}
+
+func FormatUniqueNames(names []string) string {
+ return strings.Join(NormalizeUniqueNames(names), ",")
+}
+
+func splitOnSeparators(rawNames string) []string {
+ splitNames := make([]string, 0, 1)
+
+ for _, name := range strings.FieldsFunc(rawNames, isSeparator) {
+ name = strings.TrimSpace(name)
+ if name == "" {
+ continue
+ }
+
+ splitNames = append(splitNames, name)
+ }
+
+ return splitNames
+}
+
+func isSeparator(char rune) bool {
+ return char == ',' || char == '\n' || char == '\r' || char == '\t'
+}
diff --git a/backend/internal/util/namelist/namelist_test.go b/backend/internal/util/namelist/namelist_test.go
new file mode 100644
index 00000000..ff00bf7e
--- /dev/null
+++ b/backend/internal/util/namelist/namelist_test.go
@@ -0,0 +1,39 @@
+package namelist
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func Test_ParseUniqueNames_WithBlankInput_ReturnsEmptySlice(t *testing.T) {
+ assert.Empty(t, ParseUniqueNames(""))
+ assert.Empty(t, ParseUniqueNames(" "))
+ assert.Empty(t, ParseUniqueNames(",,,"))
+ assert.NotNil(t, ParseUniqueNames(""))
+}
+
+func Test_ParseUniqueNames_WithPastedMultilineInput_ReturnsTrimmedNames(t *testing.T) {
+ pastedNames := "personnel_access_control_event,\npersonnel_real_time_location,\r\n personnel_real_time\t"
+
+ assert.Equal(
+ t,
+ []string{"personnel_access_control_event", "personnel_real_time_location", "personnel_real_time"},
+ ParseUniqueNames(pastedNames),
+ )
+}
+
+func Test_ParseUniqueNames_WithDuplicatesAndEmptyEntries_ReturnsUniqueNames(t *testing.T) {
+ assert.Equal(t, []string{"orders", "users"}, ParseUniqueNames("orders,, users ,orders"))
+}
+
+func Test_NormalizeUniqueNames_WithSeparatorsInsideEntries_SplitsThemApart(t *testing.T) {
+ storedNames := []string{"orders", "\nusers, payments", " ", "orders"}
+
+ assert.Equal(t, []string{"orders", "users", "payments"}, NormalizeUniqueNames(storedNames))
+}
+
+func Test_FormatUniqueNames_WithDirtyNames_JoinsNormalizedNamesWithCommas(t *testing.T) {
+ assert.Equal(t, "orders,users", FormatUniqueNames([]string{" orders ", "\nusers", "orders", ""}))
+ assert.Equal(t, "", FormatUniqueNames(nil))
+}
diff --git a/frontend/src/features/databases/ui/edit/EditMariaDbSpecificDataComponent.tsx b/frontend/src/features/databases/ui/edit/EditMariaDbSpecificDataComponent.tsx
index b764f04d..6c991b57 100644
--- a/frontend/src/features/databases/ui/edit/EditMariaDbSpecificDataComponent.tsx
+++ b/frontend/src/features/databases/ui/edit/EditMariaDbSpecificDataComponent.tsx
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
import { type Database, databaseApi } from '../../../../entity/databases';
import { MariadbConnectionStringParser } from '../../../../entity/databases/model/mariadb/MariadbConnectionStringParser';
+import { NAME_LIST_TOKEN_SEPARATORS, normalizeNameList } from '../../../../shared/lib';
import { ClipboardHelper } from '../../../../shared/lib/ClipboardHelper';
import { ToastHelper } from '../../../../shared/toast';
import { ClipboardPasteModalComponent } from '../../../../shared/ui';
@@ -448,16 +449,19 @@ export const EditMariaDbSpecificDataComponent = ({
setEditingDatabase({
...editingDatabase,
- mariadb: { ...editingDatabase.mariadb, excludeTables: values },
+ mariadb: { ...editingDatabase.mariadb, excludeTables: normalizeNameList(values) },
});
}}
size="small"
className="max-w-[200px] grow"
placeholder="No tables excluded"
- tokenSeparators={[',']}
+ tokenSeparators={NAME_LIST_TOKEN_SEPARATORS}
/>
- <Tooltip className="cursor-pointer" title="Table names to exclude from the backup.">
+ <Tooltip
+ className="cursor-pointer"
+ title="Table names to exclude from the backup. You can paste a list separated by commas or new lines."
+ >
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
</Tooltip>
</div>
diff --git a/frontend/src/features/databases/ui/edit/EditMongoDbSpecificDataComponent.tsx b/frontend/src/features/databases/ui/edit/EditMongoDbSpecificDataComponent.tsx
index aa0d5796..1cb66774 100644
--- a/frontend/src/features/databases/ui/edit/EditMongoDbSpecificDataComponent.tsx
+++ b/frontend/src/features/databases/ui/edit/EditMongoDbSpecificDataComponent.tsx
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
import { type Database, databaseApi } from '../../../../entity/databases';
import { MongodbConnectionStringParser } from '../../../../entity/databases/model/mongodb/MongodbConnectionStringParser';
+import { NAME_LIST_TOKEN_SEPARATORS, normalizeNameList } from '../../../../shared/lib';
import { ClipboardHelper } from '../../../../shared/lib/ClipboardHelper';
import { ToastHelper } from '../../../../shared/toast';
import { ClipboardPasteModalComponent } from '../../../../shared/ui';
@@ -476,18 +477,21 @@ export const EditMongoDbSpecificDataComponent = ({
setEditingDatabase({
...editingDatabase,
- mongodb: { ...editingDatabase.mongodb, excludeCollections: values },
+ mongodb: {
+ ...editingDatabase.mongodb,
+ excludeCollections: normalizeNameList(values),
+ },
});
}}
size="small"
className="max-w-[200px] grow"
placeholder="No collections excluded"
- tokenSeparators={[',']}
+ tokenSeparators={NAME_LIST_TOKEN_SEPARATORS}
/>
<Tooltip
className="cursor-pointer"
- title="Collection names to exclude from the backup."
+ title="Collection names to exclude from the backup. You can paste a list separated by commas or new lines."
>
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
</Tooltip>
diff --git a/frontend/src/features/databases/ui/edit/EditMySqlSpecificDataComponent.tsx b/frontend/src/features/databases/ui/edit/EditMySqlSpecificDataComponent.tsx
index d1ed0552..31026160 100644
--- a/frontend/src/features/databases/ui/edit/EditMySqlSpecificDataComponent.tsx
+++ b/frontend/src/features/databases/ui/edit/EditMySqlSpecificDataComponent.tsx
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
import { type Database, databaseApi } from '../../../../entity/databases';
import { MySqlConnectionStringParser } from '../../../../entity/databases/model/mysql/MySqlConnectionStringParser';
+import { NAME_LIST_TOKEN_SEPARATORS, normalizeNameList } from '../../../../shared/lib';
import { ClipboardHelper } from '../../../../shared/lib/ClipboardHelper';
import { ToastHelper } from '../../../../shared/toast';
import { ClipboardPasteModalComponent } from '../../../../shared/ui';
@@ -387,16 +388,19 @@ export const EditMySqlSpecificDataComponent = ({
setEditingDatabase({
...editingDatabase,
- mysql: { ...editingDatabase.mysql, excludeTables: values },
+ mysql: { ...editingDatabase.mysql, excludeTables: normalizeNameList(values) },
});
}}
size="small"
className="max-w-[200px] grow"
placeholder="No tables excluded"
- tokenSeparators={[',']}
+ tokenSeparators={NAME_LIST_TOKEN_SEPARATORS}
/>
- <Tooltip className="cursor-pointer" title="Table names to exclude from the backup.">
+ <Tooltip
+ className="cursor-pointer"
+ title="Table names to exclude from the backup. You can paste a list separated by commas or new lines."
+ >
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
</Tooltip>
</div>
diff --git a/frontend/src/features/databases/ui/edit/EditPostgreSqlLogicalSpecificDataComponent.tsx b/frontend/src/features/databases/ui/edit/EditPostgreSqlLogicalSpecificDataComponent.tsx
index bd357b81..1d33e071 100644
--- a/frontend/src/features/databases/ui/edit/EditPostgreSqlLogicalSpecificDataComponent.tsx
+++ b/frontend/src/features/databases/ui/edit/EditPostgreSqlLogicalSpecificDataComponent.tsx
@@ -9,6 +9,7 @@ import {
databaseApi,
} from '../../../../entity/databases';
import { ConnectionStringParser } from '../../../../entity/databases/model/postgresql/ConnectionStringParser';
+import { NAME_LIST_TOKEN_SEPARATORS, normalizeNameList } from '../../../../shared/lib';
import { ClipboardHelper } from '../../../../shared/lib/ClipboardHelper';
import { ToastHelper } from '../../../../shared/toast';
import { ClipboardPasteModalComponent } from '../../../../shared/ui';
@@ -645,14 +646,14 @@ export const EditPostgreSqlLogicalSpecificDataComponent = ({
...editingDatabase,
postgresqlLogical: {
...editingDatabase.postgresqlLogical,
- includeSchemas: values,
+ includeSchemas: normalizeNameList(values),
},
});
}}
size="small"
className="max-w-[200px] grow"
placeholder="All schemas (default)"
- tokenSeparators={[',']}
+ tokenSeparators={NAME_LIST_TOKEN_SEPARATORS}
/>
</div>
)}
@@ -670,19 +671,19 @@ export const EditPostgreSqlLogicalSpecificDataComponent = ({
...editingDatabase,
postgresqlLogical: {
...editingDatabase.postgresqlLogical,
- excludeTables: values,
+ excludeTables: normalizeNameList(values),
},
});
}}
size="small"
className="max-w-[200px] grow"
placeholder="No tables excluded"
- tokenSeparators={[',']}
+ tokenSeparators={NAME_LIST_TOKEN_SEPARATORS}
/>
<Tooltip
className="cursor-pointer"
- title="Tables to exclude from the backup. Use 'tablename' or 'schema.tablename'. Glob patterns are supported (e.g. 'logs_*')."
+ title="Tables to exclude from the backup. Use 'tablename' or 'schema.tablename'. Glob patterns are supported (e.g. 'logs_*'). You can paste a list separated by commas or new lines."
>
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
</Tooltip>
diff --git a/frontend/src/shared/lib/index.ts b/frontend/src/shared/lib/index.ts
index dc670ee8..7e75b5b3 100644
--- a/frontend/src/shared/lib/index.ts
+++ b/frontend/src/shared/lib/index.ts
@@ -1,4 +1,5 @@
export { formatDuration } from './formatDuration';
export { FormValidator } from './FormValidator';
+export { NAME_LIST_TOKEN_SEPARATORS, normalizeNameList } from './normalizeNameList';
export { StringUtils } from './StringUtils';
export { compareVersions, parseGitHubTag } from './version';
diff --git a/frontend/src/shared/lib/normalizeNameList.test.ts b/frontend/src/shared/lib/normalizeNameList.test.ts
new file mode 100644
index 00000000..99abccb0
--- /dev/null
+++ b/frontend/src/shared/lib/normalizeNameList.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from 'vitest';
+
+import { normalizeNameList } from './normalizeNameList';
+
+describe('normalizeNameList', () => {
+ it('trims separators glued to pasted names', () => {
+ expect(normalizeNameList(['personnel_access_control_event', '\npersonnel_real_time'])).toEqual([
+ 'personnel_access_control_event',
+ 'personnel_real_time',
+ ]);
+ });
+
+ it('splits entries that still contain separators', () => {
+ expect(normalizeNameList(['orders,\nusers\tpayments'])).toEqual([
+ 'orders',
+ 'users',
+ 'payments',
+ ]);
+ });
+
+ it('drops blank entries and duplicates', () => {
+ expect(normalizeNameList([' orders ', '', ' ', 'orders'])).toEqual(['orders']);
+ });
+});
diff --git a/frontend/src/shared/lib/normalizeNameList.ts b/frontend/src/shared/lib/normalizeNameList.ts
new file mode 100644
index 00000000..bbe5cb8b
--- /dev/null
+++ b/frontend/src/shared/lib/normalizeNameList.ts
@@ -0,0 +1,17 @@
+export const NAME_LIST_TOKEN_SEPARATORS = [',', '\n', '\r', '\t'];
+
+export const normalizeNameList = (rawNames: string[]): string[] => {
+ const normalizedNames: string[] = [];
+
+ for (const rawName of rawNames) {
+ for (const name of rawName.split(new RegExp(`[${NAME_LIST_TOKEN_SEPARATORS.join('')}]`))) {
+ const trimmedName = name.trim();
+
+ if (trimmedName && !normalizedNames.includes(trimmedName)) {
+ normalizedNames.push(trimmedName);
+ }
+ }
+ }
+
+ return normalizedNames;
+};