finalizeDatabaseSchema creates schema and compilers for a single database.
(ctx *dbContext)
| 201 | |
| 202 | // finalizeDatabaseSchema creates schema and compilers for a single database. |
| 203 | func (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) |
no test coverage detected