From c25e0125d2bb680f7eb2b0b661eff6ff51914f8f Mon Sep 17 00:00:00 2001 From: Atharva Kurhade Date: Fri, 24 Jan 2025 11:00:20 +0530 Subject: [PATCH 1/5] Added warning to import.go for target-db-schema flag --- yb-voyager/cmd/import.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/yb-voyager/cmd/import.go b/yb-voyager/cmd/import.go index 983fd2ceb3..eea9c28160 100644 --- a/yb-voyager/cmd/import.go +++ b/yb-voyager/cmd/import.go @@ -285,6 +285,10 @@ func validateTargetSchemaFlag() { } } + if tconf.Schema != "" && sourceDBType == "postgresql" { + fmt.Printf("Ignoring target-db-schema flag.\n") + } + if tconf.Schema == "" { if tconf.TargetDBType == YUGABYTEDB { tconf.Schema = YUGABYTEDB_DEFAULT_SCHEMA From 1fc218a33fbb45172f3386687f34f46c328ae7b8 Mon Sep 17 00:00:00 2001 From: Atharva Kurhade Date: Fri, 24 Jan 2025 13:05:21 +0530 Subject: [PATCH 2/5] Removed my check and modified the existing check. --- yb-voyager/cmd/import.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/yb-voyager/cmd/import.go b/yb-voyager/cmd/import.go index eea9c28160..d2446ab289 100644 --- a/yb-voyager/cmd/import.go +++ b/yb-voyager/cmd/import.go @@ -279,16 +279,12 @@ func validateTargetPortRange() { func validateTargetSchemaFlag() { // do not check for source and source-replica imports - if importerRole == TARGET_DB_IMPORTER_ROLE { + if !(importerRole == SOURCE_REPLICA_DB_IMPORTER_ROLE || importerRole == SOURCE_DB_IMPORTER_ROLE || importerRole == IMPORT_FILE_ROLE) { if tconf.Schema != "" && sourceDBType == "postgresql" { utils.ErrExit("Error: --target-db-schema flag is not valid for export from 'postgresql' db type") } } - if tconf.Schema != "" && sourceDBType == "postgresql" { - fmt.Printf("Ignoring target-db-schema flag.\n") - } - if tconf.Schema == "" { if tconf.TargetDBType == YUGABYTEDB { tconf.Schema = YUGABYTEDB_DEFAULT_SCHEMA From 2f940e4324b73525a8dbe185c2b2f903713cf91f Mon Sep 17 00:00:00 2001 From: Atharva Kurhade Date: Mon, 27 Jan 2025 12:32:25 +0530 Subject: [PATCH 3/5] Made the mentioned changes in the if statement. --- yb-voyager/cmd/import.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yb-voyager/cmd/import.go b/yb-voyager/cmd/import.go index d2446ab289..d11f147baf 100644 --- a/yb-voyager/cmd/import.go +++ b/yb-voyager/cmd/import.go @@ -279,7 +279,7 @@ func validateTargetPortRange() { func validateTargetSchemaFlag() { // do not check for source and source-replica imports - if !(importerRole == SOURCE_REPLICA_DB_IMPORTER_ROLE || importerRole == SOURCE_DB_IMPORTER_ROLE || importerRole == IMPORT_FILE_ROLE) { + if !slices.Contains([]string{SOURCE_REPLICA_DB_IMPORTER_ROLE, SOURCE_DB_IMPORTER_ROLE, IMPORT_FILE_ROLE}, importerRole) { if tconf.Schema != "" && sourceDBType == "postgresql" { utils.ErrExit("Error: --target-db-schema flag is not valid for export from 'postgresql' db type") } From 42d659d102c6183c3a839e14b33a6b0f6ea4f892 Mon Sep 17 00:00:00 2001 From: Atharva Kurhade Date: Tue, 28 Jan 2025 11:02:01 +0530 Subject: [PATCH 4/5] Added a comment specifying why the check was changed. --- yb-voyager/cmd/import.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yb-voyager/cmd/import.go b/yb-voyager/cmd/import.go index d11f147baf..a020ab849b 100644 --- a/yb-voyager/cmd/import.go +++ b/yb-voyager/cmd/import.go @@ -278,7 +278,7 @@ func validateTargetPortRange() { } func validateTargetSchemaFlag() { - // do not check for source and source-replica imports + // we want the check to run for import data to target and import schema commands if !slices.Contains([]string{SOURCE_REPLICA_DB_IMPORTER_ROLE, SOURCE_DB_IMPORTER_ROLE, IMPORT_FILE_ROLE}, importerRole) { if tconf.Schema != "" && sourceDBType == "postgresql" { utils.ErrExit("Error: --target-db-schema flag is not valid for export from 'postgresql' db type") From c01c36e7c73c79965b442c289563803fb63cb953 Mon Sep 17 00:00:00 2001 From: Atharva Kurhade Date: Tue, 28 Jan 2025 11:25:38 +0530 Subject: [PATCH 5/5] Added a more detailed comment. --- yb-voyager/cmd/import.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yb-voyager/cmd/import.go b/yb-voyager/cmd/import.go index a020ab849b..2244ea25bf 100644 --- a/yb-voyager/cmd/import.go +++ b/yb-voyager/cmd/import.go @@ -278,7 +278,9 @@ func validateTargetPortRange() { } func validateTargetSchemaFlag() { - // we want the check to run for import data to target and import schema commands + // we want to run this check only for import-data-to-target and import-schema commands. + // This is not applicable for import-data-to-source-replica (validateFFDBSchemaFlag)/import-data-to-source (no ability to pass schema). + // For import-data-file, we allow this flag and source is PG(dummy) if !slices.Contains([]string{SOURCE_REPLICA_DB_IMPORTER_ROLE, SOURCE_DB_IMPORTER_ROLE, IMPORT_FILE_ROLE}, importerRole) { if tconf.Schema != "" && sourceDBType == "postgresql" { utils.ErrExit("Error: --target-db-schema flag is not valid for export from 'postgresql' db type")