MCPcopy Index your code
hub / github.com/Shopify/ghostferry / LoadTables

Function LoadTables

table_schema_cache.go:153–233  ·  view source on GitHub ↗
(db *sql.DB, tableFilter TableFilter, columnCompressionConfig ColumnCompressionConfig, columnIgnoreConfig ColumnIgnoreConfig, forceIndexConfig ForceIndexConfig, cascadingPaginationColumnConfig *CascadingPaginationColumnConfig)

Source from the content-addressed store, hash-verified

151}
152
153func LoadTables(db *sql.DB, tableFilter TableFilter, columnCompressionConfig ColumnCompressionConfig, columnIgnoreConfig ColumnIgnoreConfig, forceIndexConfig ForceIndexConfig, cascadingPaginationColumnConfig *CascadingPaginationColumnConfig) (TableSchemaCache, error) {
154 logger := LogWithField("tag", "table_schema_cache")
155
156 tableSchemaCache := make(TableSchemaCache)
157
158 dbnames, err := showDatabases(db)
159 if err != nil {
160 logger.WithError(err).Error("failed to show databases")
161 return tableSchemaCache, err
162 }
163
164 dbnames, err = tableFilter.ApplicableDatabases(dbnames)
165 if err != nil {
166 logger.WithError(err).Error("could not apply database filter")
167 return tableSchemaCache, err
168 }
169
170 // For each database, get a list of tables from it and cache the table's schema
171 for _, dbname := range dbnames {
172 dbLog := logger.WithField("database", dbname)
173 dbLog.Debug("loading tables from database")
174 tableNames, err := showTablesFrom(db, dbname)
175 if err != nil {
176 dbLog.WithError(err).Error("failed to show tables")
177 return tableSchemaCache, err
178 }
179
180 var tableSchemas []*TableSchema
181
182 for _, table := range tableNames {
183 tableLog := dbLog.WithField("table", table)
184 tableLog.Debug("fetching table schema")
185 tableSchema, err := schema.NewTableFromSqlDB(db.DB, dbname, table)
186 if err != nil {
187 tableLog.WithError(err).Error("cannot fetch table schema from source db")
188 return tableSchemaCache, err
189 }
190
191 // Filter out invisible indexes
192 visibleIndexes := make([]*schema.Index, 0, len(tableSchema.Indexes))
193 for _, index := range tableSchema.Indexes {
194 if index.Visible {
195 visibleIndexes = append(visibleIndexes, index)
196 }
197 }
198 tableSchema.Indexes = visibleIndexes
199
200 tableSchemas = append(tableSchemas, &TableSchema{
201 Table: tableSchema,
202 CompressedColumnsForVerification: columnCompressionConfig.CompressedColumnsFor(dbname, table),
203 IgnoredColumnsForVerification: columnIgnoreConfig.IgnoredColumnsFor(dbname, table),
204 ForcedIndexForVerification: forceIndexConfig.IndexFor(dbname, table),
205 })
206 }
207
208 tableSchemas, err = tableFilter.ApplicableTables(tableSchemas)
209 if err != nil {
210 return tableSchemaCache, nil

Calls 15

LogWithFieldFunction · 0.85
showDatabasesFunction · 0.85
showTablesFromFunction · 0.85
CompressedColumnsForMethod · 0.80
IgnoredColumnsForMethod · 0.80
IndexForMethod · 0.80
paginationKeyColumnMethod · 0.80
AllTableNamesMethod · 0.80
ErrorMethod · 0.65
WithErrorMethod · 0.65
ApplicableDatabasesMethod · 0.65
WithFieldMethod · 0.65