MCPcopy
hub / github.com/dosco/graphjin / finalizeDatabaseSchema

Method finalizeDatabaseSchema

core/init_multidb.go:203–332  ·  view source on GitHub ↗

finalizeDatabaseSchema creates schema and compilers for a single database.

(ctx *dbContext)

Source from the content-addressed store, hash-verified

201
202// finalizeDatabaseSchema creates schema and compilers for a single database.
203func (gj *graphjinEngine) finalizeDatabaseSchema(ctx *dbContext) error {
204 if ctx.dbinfo == nil {
205 return nil
206 }
207
208 // Graceful degradation: if no tables were discovered, log a warning
209 // and return nil — the watcher will re-check periodically.
210 if len(ctx.dbinfo.Tables) == 0 {
211 ps := gj.conf.DBSchemaPollDuration
212 if ps < 5*time.Second {
213 ps = 10 * time.Second
214 }
215 gj.log.Printf("warning: no tables found in database '%s', rechecking every %s",
216 ctx.dbinfo.Name, ps)
217 return nil
218 }
219
220 // Process table config info (order-by config, etc.) for tables belonging to this database.
221 // Also fill in empty Schema fields and handle Oracle lowercase.
222 {
223 schema := ctx.dbinfo.Schema
224 for i, t := range gj.conf.Tables {
225 // Only process tables that belong to this database
226 if t.Database != "" && t.Database != ctx.name {
227 continue
228 }
229 // Oracle requires lowercase identifiers
230 if ctx.dbtype == "oracle" {
231 gj.conf.Tables[i].Schema = strings.ToLower(gj.conf.Tables[i].Schema)
232 gj.conf.Tables[i].Name = strings.ToLower(gj.conf.Tables[i].Name)
233 gj.conf.Tables[i].Table = strings.ToLower(gj.conf.Tables[i].Table)
234 t = gj.conf.Tables[i]
235 }
236 // Fill in empty Schema from dbinfo.Schema
237 if t.Schema == "" {
238 gj.conf.Tables[i].Schema = schema
239 t.Schema = schema
240 }
241 // Skip aliases
242 if t.Table != "" && t.Type == "" {
243 continue
244 }
245 if err := gj.addTableInfo(t); err != nil {
246 return err
247 }
248 }
249 }
250
251 // Tag all discovered tables with the owning database name
252 for i := range ctx.dbinfo.Tables {
253 ctx.dbinfo.Tables[i].Database = ctx.name
254 }
255
256 // Ensure conf.Tables has entries for all discovered tables in this database.
257 // Without this, groupRootsByDatabase cannot route queries/mutations to
258 // non-default databases because it only checks conf.Tables.
259 // This runs on both init and Reload(), so dynamic config changes are covered.
260 gj.ensureDiscoveredTablesInConfig(ctx)

Callers 4

finalizeAllDatabasesMethod · 0.95
initDBContextMethod · 0.95

Calls 15

addTableInfoMethod · 0.95
collectDBInfosMethod · 0.95
addTablesFunction · 0.85
addForeignKeysFunction · 0.85
addFullTextColumnsFunction · 0.85
addFunctionsFunction · 0.85
addCodeSQLVirtualColumnsFunction · 0.85
hideRawCodeSQLTablesFunction · 0.85
getDBTableAliasesFunction · 0.85
addRolesFunction · 0.85

Tested by

no test coverage detected