Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions database/drivers/postgres/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -535,7 +537,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for this change? Might a newline not be a significant part of the comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is \n in comment in pg, gnorm will throw error:

error calling makeTable: failed to render from pipe delimited bytes: record on line 4: wrong number of fields

This is about to fix it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just ran into this issue with some of the comments in my database. Can this be merged?

Copy link

@maxhawkins maxhawkins Nov 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then again, this might not be the right fix. I believe I ran into this issue when running gnorm preview on a comment containing | and ). Is there an existing issue ticket for this?

Copy link
Author

@sillydong sillydong Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr was about to fix \n in comment. I didn't meet the | or ) issue before.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For | and ), may be needs more strings.Replace

r.Comment = replaced
results = append(results, r)
}
}
Expand Down Expand Up @@ -585,7 +588,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)
}
}
Expand Down
10 changes: 10 additions & 0 deletions environ/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -138,6 +139,15 @@ func numbers(start, end int) data.Strings {
return s
}

// 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++ {
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) {
Expand Down