From b7f9e98816cd0b72363dfa50f68b77412a65ccd2 Mon Sep 17 00:00:00 2001 From: Bob Vawter Date: Thu, 19 Sep 2024 13:40:58 -0400 Subject: [PATCH] schemawatch: Ignore hidden Oracle Database columns This change updates the column inspection query to also consider the HIDDEN_COLUMN value when deciding which columns to ignore. --- internal/target/schemawatch/coldata.go | 4 +++- internal/target/schemawatch/coldata_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/target/schemawatch/coldata.go b/internal/target/schemawatch/coldata.go index 9c399a3a6..ef37ab371 100644 --- a/internal/target/schemawatch/coldata.go +++ b/internal/target/schemawatch/coldata.go @@ -245,6 +245,7 @@ WITH atc AS ( ELSE DATA_TYPE END DATA_TYPE, DATA_DEFAULT, + HIDDEN_COLUMN, VIRTUAL_COLUMN FROM ALL_TAB_COLS ), pk_cols AS (SELECT OWNER, TABLE_NAME, CONSTRAINT_NAME FROM ALL_CONSTRAINTS WHERE CONSTRAINT_TYPE='P'), @@ -254,7 +255,8 @@ SELECT /*+ gather_plan_statistics */ COALESCE(IS_PK, 'f'), atc.DATA_TYPE, atc.DATA_DEFAULT, - CASE WHEN atc.VIRTUAL_COLUMN = 'YES' THEN 't' ELSE 'f' END + CASE WHEN (atc.HIDDEN_COLUMN = 'YES' OR atc.VIRTUAL_COLUMN = 'YES') + THEN 't' ELSE 'f' END FROM atc LEFT JOIN pk_cols USING (OWNER, TABLE_NAME) LEFT JOIN acc USING (OWNER, TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME) diff --git a/internal/target/schemawatch/coldata_test.go b/internal/target/schemawatch/coldata_test.go index 2529ec5e5..e31f8354c 100644 --- a/internal/target/schemawatch/coldata_test.go +++ b/internal/target/schemawatch/coldata_test.go @@ -306,6 +306,18 @@ func TestGetColumns(t *testing.T) { "d", "VARCHAR2(1 CHAR)", ), }, + // Verify that hidden columns are ignored. + { + products: []types.Product{types.ProductOracle}, + tableSchema: "a INT PRIMARY KEY, b VARCHAR2(1 CHAR) DEFAULT 'n' NULL, c INT INVISIBLE", + primaryKeys: []string{"a"}, + dataCols: []string{"b", "ignored_c"}, + types: ident.MapOf[string]( + "a", "NUMBER", + "b", "VARCHAR2(1 CHAR)", + "c", "NUMBER", + ), + }, // Check default value extraction { products: []types.Product{types.ProductCockroachDB, types.ProductMariaDB,