| 84 | } |
| 85 | |
| 86 | func NewDatabaseMetadata( |
| 87 | metadata *storepb.DatabaseSchemaMetadata, |
| 88 | schema []byte, |
| 89 | config *storepb.DatabaseConfig, |
| 90 | engine storepb.Engine, |
| 91 | isObjectCaseSensitive bool, |
| 92 | ) *DatabaseMetadata { |
| 93 | isDetailCaseSensitive := getIsDetailCaseSensitive(engine) |
| 94 | dbMetadata := &DatabaseMetadata{ |
| 95 | proto: metadata, |
| 96 | rawDump: schema, |
| 97 | config: config, |
| 98 | isObjectCaseSensitive: isObjectCaseSensitive, |
| 99 | isDetailCaseSensitive: isDetailCaseSensitive, |
| 100 | searchPath: ParsePGConfiguredSearchPath(metadata.SearchPath), |
| 101 | internal: make(map[string]*SchemaMetadata), |
| 102 | linkedDatabase: make(map[string]*storepb.LinkedDatabaseMetadata), |
| 103 | } |
| 104 | |
| 105 | // Build a map of schema catalogs for quick lookup |
| 106 | schemaCatalogMap := make(map[string]*storepb.SchemaCatalog) |
| 107 | if config != nil { |
| 108 | for _, schemaCatalog := range config.Schemas { |
| 109 | schemaCatalogMap[schemaCatalog.Name] = schemaCatalog |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // Build schema metadata maps |
| 114 | for _, s := range metadata.Schemas { |
| 115 | // Get matching schema catalog if it exists |
| 116 | schemaCatalog := schemaCatalogMap[s.Name] |
| 117 | |
| 118 | // Build a map of table catalogs for this schema |
| 119 | tableCatalogMap := make(map[string]*storepb.TableCatalog) |
| 120 | if schemaCatalog != nil { |
| 121 | for _, tableCatalog := range schemaCatalog.Tables { |
| 122 | tableCatalogMap[tableCatalog.Name] = tableCatalog |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | schemaMetadata := &SchemaMetadata{ |
| 127 | isObjectCaseSensitive: isObjectCaseSensitive, |
| 128 | isDetailCaseSensitive: isDetailCaseSensitive, |
| 129 | internalTables: make(map[string]*TableMetadata), |
| 130 | internalExternalTable: make(map[string]*ExternalTableMetadata), |
| 131 | internalViews: make(map[string]*storepb.ViewMetadata), |
| 132 | internalMaterializedView: make(map[string]*storepb.MaterializedViewMetadata), |
| 133 | internalProcedures: make(map[string]*storepb.ProcedureMetadata), |
| 134 | internalPackages: make(map[string]*storepb.PackageMetadata), |
| 135 | internalSequences: make(map[string]*storepb.SequenceMetadata), |
| 136 | proto: s, |
| 137 | config: schemaCatalog, |
| 138 | } |
| 139 | for _, table := range s.Tables { |
| 140 | tableCatalog := tableCatalogMap[table.Name] |
| 141 | tables, names := buildTablesMetadata(table, tableCatalog, isDetailCaseSensitive) |
| 142 | for i, table := range tables { |
| 143 | tableID := normalizeNameByCaseSensitivity(names[i], isObjectCaseSensitive) |