Skip to content

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

chore: support view for access control feature (#7192)

rebelice5d148039668c
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index 7d4c1dcc87..0fa9706a17 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -1649,14 +1649,14 @@ func (s *SQLService) extractResourceList(ctx context.Context, engine parser.Engi
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get database schema %v in instance %v, err: %v", resource.Database, instance.ResourceID, err)
}
- if !resourceDBSchema.TableExists(resource.Schema, resource.Table) {
+ if !resourceDBSchema.TableExists(resource.Schema, resource.Table) && !resourceDBSchema.ViewExists(resource.Schema, resource.Table) {
// If table not found, we regard it as a CTE/alias/... and skip.
continue
}
result = append(result, resource)
continue
}
- if !dbSchema.TableExists(resource.Schema, resource.Table) {
+ if !dbSchema.TableExists(resource.Schema, resource.Table) && !dbSchema.ViewExists(resource.Schema, resource.Table) {
// If table not found, skip.
continue
}
@@ -1689,7 +1689,7 @@ func (s *SQLService) extractResourceList(ctx context.Context, engine parser.Engi
continue
}
- if !dbSchema.TableExists(resource.Schema, resource.Table) {
+ if !dbSchema.TableExists(resource.Schema, resource.Table) && !dbSchema.ViewExists(resource.Schema, resource.Table) {
// If table not found, skip.
continue
}
@@ -1748,7 +1748,7 @@ func (s *SQLService) extractResourceList(ctx context.Context, engine parser.Engi
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get database schema %v in instance %v, err: %v", resource.Database, instance.ResourceID, err)
}
- if !resourceDBSchema.TableExists(resource.Schema, resource.Table) {
+ if !resourceDBSchema.TableExists(resource.Schema, resource.Table) && !resourceDBSchema.ViewExists(resource.Schema, resource.Table) {
// If table not found, we regard it as a CTE/alias/... and skip.
continue
}
@@ -1756,7 +1756,7 @@ func (s *SQLService) extractResourceList(ctx context.Context, engine parser.Engi
continue
}
- if !dbSchema.TableExists(resource.Schema, resource.Table) {
+ if !dbSchema.TableExists(resource.Schema, resource.Table) && !dbSchema.ViewExists(resource.Schema, resource.Table) {
// If table not found, skip.
continue
}
@@ -1808,14 +1808,14 @@ func (s *SQLService) extractResourceList(ctx context.Context, engine parser.Engi
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get database schema %v in instance %v, err: %v", resource.Database, instance.ResourceID, err)
}
- if !resourceDBSchema.TableExists(resource.Schema, resource.Table) {
+ if !resourceDBSchema.TableExists(resource.Schema, resource.Table) && !resourceDBSchema.ViewExists(resource.Schema, resource.Table) {
// If table not found, we regard it as a CTE/alias/... and skip.
continue
}
result = append(result, resource)
continue
}
- if !dbSchema.TableExists(resource.Schema, resource.Table) {
+ if !dbSchema.TableExists(resource.Schema, resource.Table) && !dbSchema.ViewExists(resource.Schema, resource.Table) {
// If table not found, skip.
continue
}
diff --git a/backend/store/db_schema.go b/backend/store/db_schema.go
index cc6cb80dc7..dc34df1f1b 100644
--- a/backend/store/db_schema.go
+++ b/backend/store/db_schema.go
@@ -33,6 +33,21 @@ func (s *DBSchema) TableExists(schemaName string, tableName string) bool {
return false
}
+// ViewExists checks if the view exists.
+func (s *DBSchema) ViewExists(schemaName string, name string) bool {
+ for _, schema := range s.Metadata.Schemas {
+ if schema.Name != schemaName {
+ continue
+ }
+ for _, view := range schema.Views {
+ if view.Name == name {
+ return true
+ }
+ }
+ }
+ return false
+}
+
// CompactText returns the compact text representation of the database schema.
func (s *DBSchema) CompactText() (string, error) {
if s.Metadata == nil {