Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: remove functions field from SchemaMetadata (#18152)
Danny Xu6081129d52b3
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.goindex c2d58f73e5..6f7d2abb88 100644--- a/backend/api/v1/database_service.go+++ b/backend/api/v1/database_service.go@@ -1196,7 +1196,13 @@ func (s *DatabaseService) GetSchemaString(ctx context.Context, req *connect.Requif schemaMetadata == nil {return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("schema %q not found", req.Msg.Schema))}- functionMetadata := schemaMetadata.GetFunction(req.Msg.Object)+ var functionMetadata *storepb.FunctionMetadata+ for _, fn := range schemaMetadata.GetProto().GetFunctions() {+ if fn.Name == req.Msg.Object {+ functionMetadata = fn+ break+ }+ }if functionMetadata == nil {return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("function %q not found", req.Msg.Object))}diff --git a/backend/plugin/schema/differ.go b/backend/plugin/schema/differ.goindex 7e182e0980..9dbb27970f 100644--- a/backend/plugin/schema/differ.go+++ b/backend/plugin/schema/differ.go@@ -430,7 +430,7 @@ func addNewSchemaObjects(diff *MetadataDiff, schemaName string, schema *model.Sc}// Add all functions- for _, function := range schema.ListFunctions() {+ for _, function := range schema.GetProto().GetFunctions() {if !function.GetSkipDump() {// Use signature if available, otherwise fall back to namefunctionName := function.Signature@@ -1690,7 +1690,7 @@ func compareFunctions(engine storepb.Engine, diff *MetadataDiff, schemaName stri// Group functions by signature to properly match overloaded functions// Build map of old functions by signatureoldFuncsBySignature := make(map[string]*storepb.FunctionMetadata)- for _, fn := range oldSchema.ListFunctions() {+ for _, fn := range oldSchema.GetProto().GetFunctions() {if !fn.GetSkipDump() {sig := fn.Signatureif sig == "" {@@ -1702,7 +1702,7 @@ func compareFunctions(engine storepb.Engine, diff *MetadataDiff, schemaName stri// Build map of new functions by signaturenewFuncsBySignature := make(map[string]*storepb.FunctionMetadata)- for _, fn := range newSchema.ListFunctions() {+ for _, fn := range newSchema.GetProto().GetFunctions() {if !fn.GetSkipDump() {sig := fn.Signatureif sig == "" {diff --git a/backend/store/model/database.go b/backend/store/model/database.goindex e32d151807..984fceb01e 100644--- a/backend/store/model/database.go+++ b/backend/store/model/database.go@@ -36,11 +36,9 @@ type SchemaMetadata struct {internalExternalTable map[string]*ExternalTableMetadatainternalViews map[string]*storepb.ViewMetadatainternalMaterializedView map[string]*storepb.MaterializedViewMetadata- // Store internal functions by list to take care of the overloadings.- functions []*storepb.FunctionMetadata- internalProcedures map[string]*storepb.ProcedureMetadata- internalSequences map[string]*storepb.SequenceMetadata- internalPackages map[string]*storepb.PackageMetadata+ internalProcedures map[string]*storepb.ProcedureMetadata+ internalSequences map[string]*storepb.SequenceMetadata+ internalPackages map[string]*storepb.PackageMetadataproto *storepb.SchemaMetadata}@@ -152,7 +150,6 @@ func NewDatabaseMetadata(viewID := normalizeNameByCaseSensitivity(materializedView.Name, isObjectCaseSensitive)schemaMetadata.internalMaterializedView[viewID] = materializedView}- schemaMetadata.functions = s.Functionsfor _, procedure := range s.Procedures {procedureID := normalizeNameByCaseSensitivity(procedure.Name, isDetailCaseSensitive)schemaMetadata.internalProcedures[procedureID] = procedure@@ -431,14 +428,11 @@ func (s *SchemaMetadata) GetExternalTable(name string) *ExternalTableMetadata {return s.internalExternalTable[nameID]}-// ListFunctions lists the functions.-func (s *SchemaMetadata) ListFunctions() []*storepb.FunctionMetadata {- return s.functions-}-// GetFunction gets the function by name.+// Note: For overloaded functions, this returns the first match by name only.+// Use signature-based lookup for precise matching.func (s *SchemaMetadata) GetFunction(name string) *storepb.FunctionMetadata {- for _, function := range s.functions {+ for _, function := range s.proto.GetFunctions() {if s.isDetailCaseSensitive {if function.Name == name {return function@@ -501,17 +495,6 @@ func (s *SchemaMetadata) ListProcedureNames() []string {return result}-// ListFunctionNames lists the function names.-func (s *SchemaMetadata) ListFunctionNames() []string {- var result []string- for _, function := range s.functions {- result = append(result, function.GetName())- }-- slices.Sort(result)- return result-}-// ListViewNames lists the view names.func (s *SchemaMetadata) ListViewNames() []string {var result []stringdiff --git a/backend/store/model/pg_searcher.go b/backend/store/model/pg_searcher.goindex 67494b595b..2f192ee21f 100644--- a/backend/store/model/pg_searcher.go+++ b/backend/store/model/pg_searcher.go@@ -138,7 +138,7 @@ func (s *DatabaseSearcher) SearchFunctions(name string) ([]string, []*storepb.Fuif schema == nil {continue}- for _, function := range schema.functions {+ for _, function := range schema.GetProto().GetFunctions() {if s.db.isDetailCaseSensitive {if function.Name == name {schemas = append(schemas, schema.proto.Name)@@ -276,7 +276,7 @@ func (d *DatabaseMetadata) SearchFunctions(searchPath []string, name string) ([]if schema == nil {continue}- for _, function := range schema.functions {+ for _, function := range schema.GetProto().GetFunctions() {if d.isDetailCaseSensitive {if function.Name == name {schemas = append(schemas, schema.proto.Name)