Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: move the Oracle to use schemaList instead of tableList in databaseSchema (#7809)

h3n4l493cd602e218
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index ff92e02269..7aa1f45d8d 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -1397,6 +1397,9 @@ func (s *SQLService) getSensitiveSchemaInfo(ctx context.Context, instance *store
if instance.Engine == db.Oracle || instance.Engine == db.DM {
for _, schema := range dbSchema.Metadata.Schemas {
databaseSchema := db.DatabaseSchema{
+ Name: schema.Name,
+ }
+ schemaSchema := db.SchemaSchema{
Name: schema.Name,
TableList: []db.TableSchema{},
}
@@ -1419,8 +1422,9 @@ func (s *SQLService) getSensitiveSchemaInfo(ctx context.Context, instance *store
Sensitive: sensitive,
})
}
- databaseSchema.TableList = append(databaseSchema.TableList, tableSchema)
+ schemaSchema.TableList = append(schemaSchema.TableList, tableSchema)
}
+ databaseSchema.SchemaList = append(databaseSchema.SchemaList, schemaSchema)
result.DatabaseList = append(result.DatabaseList, databaseSchema)
}
continue
diff --git a/backend/plugin/db/driver.go b/backend/plugin/db/driver.go
index de84de14c1..bdbe4646b3 100644
--- a/backend/plugin/db/driver.go
+++ b/backend/plugin/db/driver.go
@@ -630,7 +630,7 @@ type DatabaseSchema struct {
SchemaList []SchemaSchema
// !!DEPRECATED!!, should use SchemaList instead.
- // TODO(rebelice/zp): Migrate PostgreSQL/Oracle to SchemaList.
+ // TODO(rebelice/zp): Migrate PostgreSQL to SchemaList.
TableList []TableSchema
ViewList []ViewSchema
}
diff --git a/backend/plugin/db/util/driverutil_test.go b/backend/plugin/db/util/driverutil_test.go
index 6042c59f77..7a677d778b 100644
--- a/backend/plugin/db/util/driverutil_test.go
+++ b/backend/plugin/db/util/driverutil_test.go
@@ -1232,25 +1232,30 @@ func TestPLSQLExtractSensitiveField(t *testing.T) {
DatabaseList: []db.DatabaseSchema{
{
Name: defaultSchema,
- TableList: []db.TableSchema{
+ SchemaList: []db.SchemaSchema{
{
- Name: "T",
- ColumnList: []db.ColumnInfo{
- {
- Name: "A",
- Sensitive: true,
- },
- {
- Name: "B",
- Sensitive: false,
- },
- {
- Name: "C",
- Sensitive: false,
- },
+ Name: defaultSchema,
+ TableList: []db.TableSchema{
{
- Name: "D",
- Sensitive: true,
+ Name: "T",
+ ColumnList: []db.ColumnInfo{
+ {
+ Name: "A",
+ Sensitive: true,
+ },
+ {
+ Name: "B",
+ Sensitive: false,
+ },
+ {
+ Name: "C",
+ Sensitive: false,
+ },
+ {
+ Name: "D",
+ Sensitive: true,
+ },
+ },
},
},
},
diff --git a/backend/plugin/db/util/mask_sensitive_data.go b/backend/plugin/db/util/mask_sensitive_data.go
index 42682abe10..3bc8c257ad 100644
--- a/backend/plugin/db/util/mask_sensitive_data.go
+++ b/backend/plugin/db/util/mask_sensitive_data.go
@@ -66,6 +66,17 @@ func extractSensitiveField(dbType db.Type, statement string, currentDatabase str
}
return result, nil
case db.Oracle, db.DM:
+ for _, database := range schemaInfo.DatabaseList {
+ if len(database.SchemaList) == 0 {
+ continue
+ }
+ if len(database.SchemaList) > 1 {
+ return nil, errors.Errorf("Oracle schema info should only have one schema per database, but got %d, %v", len(database.SchemaList), database.SchemaList)
+ }
+ if database.SchemaList[0].Name != database.Name {
+ return nil, errors.Errorf("Oracle schema info should have the same database name and schema name, but got %s and %s", database.Name, database.SchemaList[0].Name)
+ }
+ }
extractor := &sensitiveFieldExtractor{
currentDatabase: currentDatabase,
schemaInfo: schemaInfo,
diff --git a/backend/plugin/db/util/mask_sensitive_data_plsql.go b/backend/plugin/db/util/mask_sensitive_data_plsql.go
index 544f369ca1..43bf2a3fdd 100644
--- a/backend/plugin/db/util/mask_sensitive_data_plsql.go
+++ b/backend/plugin/db/util/mask_sensitive_data_plsql.go
@@ -1177,7 +1177,11 @@ func (extractor *sensitiveFieldExtractor) plsqlFindTableSchema(schemaName, table
if schema.Name != schemaName {
continue
}
- for _, table := range schema.TableList {
+ if len(schema.SchemaList) == 0 {
+ continue
+ }
+ tableList := schema.SchemaList[0].TableList
+ for _, table := range tableList {
if table.Name == tableName {
return table, nil
}