Skip to content

Commit 5d40fe7

Browse files
authored
Validate table Name property matches key in plugin's TableMap. Closes #355
1 parent d1d2097 commit 5d40fe7

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

cache/query_cache.go

+2
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ func (c *QueryCache) getKeyColumnsForTable(table string) map[string]*proto.KeyCo
304304
for _, k := range append(tableSchema.ListCallKeyColumnList, tableSchema.GetCallKeyColumnList...) {
305305
res[k.Name] = k
306306
}
307+
} else {
308+
log.Printf("[WARN] getKeyColumnsForTable found NO SCHEMA FOR %s", table)
307309
}
308310
return res
309311
}

plugin/plugin.go

+3
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ func (p *Plugin) ensureCache() error {
416416
}
417417

418418
func (p *Plugin) buildSchema() (map[string]*proto.TableSchema, error) {
419+
log.Printf("[TRACE] buildSchema")
420+
defer log.Printf("[TRACE] buildSchema complete")
421+
419422
// the connection property must be set already
420423
if p.Connection == nil {
421424
return nil, fmt.Errorf("plugin.GetSchema called before setting connection config")

plugin/plugin_validate.go

+14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ func (p *Plugin) Validate() string {
2929
log.Printf("[TRACE] validate DefaultIgnoreConfig")
3030
validationErrors = append(validationErrors, p.DefaultIgnoreConfig.Validate(nil)...)
3131

32+
log.Printf("[TRACE] validate table names")
33+
validationErrors = append(validationErrors, p.validateTableNames()...)
34+
3235
log.Printf("[TRACE] plugin has %d validation errors", len(validationErrors))
3336
return strings.Join(validationErrors, "\n")
3437
}
38+
39+
// validate that table names are consistent with their key in the table map
40+
func (p *Plugin) validateTableNames() []string {
41+
var validationErrors []string
42+
for tableName, table := range p.TableMap {
43+
if table.Name != tableName {
44+
validationErrors = append(validationErrors, fmt.Sprintf("table '%s' has inconsistent Name property: '%s'", tableName, table.Name))
45+
}
46+
}
47+
return validationErrors
48+
}

0 commit comments

Comments
 (0)