From a142afa618ef9a694cc4acd294fa52c92cb0ec00 Mon Sep 17 00:00:00 2001 From: "Chen.Zhidong" Date: Fri, 20 Apr 2018 10:00:23 +0800 Subject: [PATCH 1/4] replace \n to space in postgresql comments Fix: error calling makeTable: failed to render from pipe delimited bytes: record on line 4: wrong number of fields --- database/drivers/postgres/parse.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/database/drivers/postgres/parse.go b/database/drivers/postgres/parse.go index 25fec4f..1131a2d 100644 --- a/database/drivers/postgres/parse.go +++ b/database/drivers/postgres/parse.go @@ -535,7 +535,8 @@ func queryColumnComments(log *log.Logger, db *sql.DB, schemaNames []string) ([]c } if c.Valid { - r.Comment = c.String + replaced := strings.Replace(c.String, "\n", " ", -1) + r.Comment = replaced results = append(results, r) } } @@ -585,7 +586,8 @@ func queryTableComments(log *log.Logger, db *sql.DB, schemaNames []string) ([]ta } if c.Valid { - r.Comment = c.String + replaced := strings.Replace(c.String, "\n", " ", -1) + r.Comment = replaced results = append(results, r) } } From 92b61744fd4b470ee5e3d88fd11f51e9095f8e45 Mon Sep 17 00:00:00 2001 From: "Chen.Zhidong" Date: Fri, 20 Apr 2018 10:01:46 +0800 Subject: [PATCH 2/4] check if schemaname exists to avoid panic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old way may cause panic when the retrieved table name don’t contain schema name. --- database/drivers/postgres/parse.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/database/drivers/postgres/parse.go b/database/drivers/postgres/parse.go index 1131a2d..aca1fc2 100644 --- a/database/drivers/postgres/parse.go +++ b/database/drivers/postgres/parse.go @@ -482,7 +482,9 @@ func queryIndexes(log *log.Logger, db *sql.DB, schemaNames []string) ([]indexRes // postgres prepends schema onto table name if outside of public schema if r.SchemaName != "public" { - r.TableName = r.TableName[len(r.SchemaName)+1:] + if strings.Contains(r.TableName, r.SchemaName) { + r.TableName = r.TableName[len(r.SchemaName)+1:] + } } results = append(results, r) From d16c13dc3f34c4836fe9c1da24ba04161839a1a2 Mon Sep 17 00:00:00 2001 From: "Chen.Zhidong" Date: Fri, 20 Apr 2018 10:02:07 +0800 Subject: [PATCH 3/4] add step support for convenience --- environ/funcs.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/environ/funcs.go b/environ/funcs.go index 1cc748e..059c4ac 100644 --- a/environ/funcs.go +++ b/environ/funcs.go @@ -38,6 +38,7 @@ var FuncMap = map[string]interface{}{ "makeMap": makeMap, "makeSlice": makeSlice, "numbers": numbers, + "steps": steps, "pascal": kace.Pascal, "repeat": strings.Repeat, "replace": strings.Replace, @@ -138,6 +139,15 @@ func numbers(start, end int) data.Strings { return s } +// steps returns a live of strings of the numbers start with size of len +func steps(start, len int) data.Strings { + var s data.Strings + for x := 0; x < len; x++ { + s = append(s, strconv.Itoa(start+x)) + } + return s +} + // Plugin returns a function which can be used in templates for executing plugins, // dirs is the list of directories which are used fo plugin lookup. func Plugin(dirs []string) func(string, string, interface{}) (interface{}, error) { From 0de6265997f5ff092f66b5cfea8d3ec8f5ecaa2b Mon Sep 17 00:00:00 2001 From: "Chen.Zhidong" Date: Sun, 22 Apr 2018 10:42:58 +0800 Subject: [PATCH 4/4] fix comment --- environ/funcs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environ/funcs.go b/environ/funcs.go index 059c4ac..f4f5b14 100644 --- a/environ/funcs.go +++ b/environ/funcs.go @@ -139,7 +139,7 @@ func numbers(start, end int) data.Strings { return s } -// steps returns a live of strings of the numbers start with size of len +// steps returns a slice of strings of the numbers from start with length of len func steps(start, len int) data.Strings { var s data.Strings for x := 0; x < len; x++ {