From cdee9c71ce76f13e227d27c6cbe3bb4d5fb2f576 Mon Sep 17 00:00:00 2001 From: Martijn Pieters Date: Wed, 19 Jun 2024 12:00:13 +0100 Subject: [PATCH] Address lint errors - Remove unused config functions (these were moved to `filter.go` in 1bed38d) - Use entries of mongodb bson.D result directly instead of using the deprecated Map method. - Don't ignore err results from utility functions. --- config/config.go | 52 -------------------------------------- drivers/mongodb/mongodb.go | 3 ++- drivers/mysql/mysql.go | 3 +++ drivers/sqlite/sqlite.go | 3 +++ 4 files changed, 8 insertions(+), 53 deletions(-) diff --git a/config/config.go b/config/config.go index 3de9102b9..21361f9c8 100644 --- a/config/config.go +++ b/config/config.go @@ -550,47 +550,6 @@ func (c *Config) mergeDictFromSchema(s *schema.Schema) { } } -func excludeTableFromSchema(name string, s *schema.Schema) error { - // Tables - tables := []*schema.Table{} - for _, t := range s.Tables { - if t.Name != name { - tables = append(tables, t) - } - for _, c := range t.Columns { - // ChildRelations - childRelations := []*schema.Relation{} - for _, r := range c.ChildRelations { - if r.Table.Name != name && r.ParentTable.Name != name { - childRelations = append(childRelations, r) - } - } - c.ChildRelations = childRelations - - // ParentRelations - parentRelations := []*schema.Relation{} - for _, r := range c.ParentRelations { - if r.Table.Name != name && r.ParentTable.Name != name { - parentRelations = append(parentRelations, r) - } - } - c.ParentRelations = parentRelations - } - } - s.Tables = tables - - // Relations - relations := []*schema.Relation{} - for _, r := range s.Relations { - if r.Table.Name != name && r.ParentTable.Name != name { - relations = append(relations, r) - } - } - s.Relations = relations - - return nil -} - // MaskedDSN return DSN mask password func (c *Config) MaskedDSN() (string, error) { u, err := url.Parse(c.DSN.URL) @@ -905,17 +864,6 @@ func detectPKFK(s *schema.Schema) error { return nil } -func matchLabels(il []string, l schema.Labels) bool { - for _, ll := range l { - for _, ill := range il { - if wildcard.MatchSimple(ill, ll.Name) { - return true - } - } - } - return false -} - func match(s []string, e string) bool { _, m := matchLength(s, e) return m diff --git a/drivers/mongodb/mongodb.go b/drivers/mongodb/mongodb.go index d822004dd..17b2745fa 100644 --- a/drivers/mongodb/mongodb.go +++ b/drivers/mongodb/mongodb.go @@ -95,7 +95,8 @@ func (d *Mongodb) listFields(collection *mongo.Collection) ([]*schema.Column, er return columns, err } total += 1 - for key, value := range result.Map() { + for _, entry := range result { + key, value := entry.Key, entry.Value var valueType string switch value.(type) { case string: diff --git a/drivers/mysql/mysql.go b/drivers/mysql/mysql.go index 3b7e35b48..b28518355 100644 --- a/drivers/mysql/mysql.go +++ b/drivers/mysql/mysql.go @@ -499,6 +499,9 @@ WHERE t.table_schema = ? }) for _, r := range relations { strColumns, strParentTable, strParentColumns, err := parseFK(r.Def) + if err != nil { + return err + } for _, c := range strColumns { column, err := r.Table.FindColumnByName(c) if err != nil { diff --git a/drivers/sqlite/sqlite.go b/drivers/sqlite/sqlite.go index a32b0e46f..ede5a48ce 100644 --- a/drivers/sqlite/sqlite.go +++ b/drivers/sqlite/sqlite.go @@ -366,6 +366,9 @@ SELECT name, sql FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ?; // Relations for _, r := range relations { strColumns, strParentTable, strParentColumns, err := parseFK(r.Def) + if err != nil { + return err + } for _, c := range strColumns { column, err := r.Table.FindColumnByName(c) if err != nil {