Skip to content

Commit

Permalink
Merge pull request #53 from k1LoW/fix-multi-fk-dot
Browse files Browse the repository at this point in the history
Fix relation rendering of multi-columns foreign key
  • Loading branch information
k1LoW committed Aug 8, 2018
2 parents 2b9b65c + 560603a commit b6b69ca
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 9 deletions.
17 changes: 15 additions & 2 deletions output/dot/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ func OutputTable(wr io.Writer, t *schema.Table) error {
encountered[r.ParentTable.Name] = true
tables = append(tables, r.ParentTable)
}
relations = append(relations, r)
if !contains(relations, r) {
relations = append(relations, r)
}
}
for _, r := range c.ChildRelations {
if !encountered[r.Table.Name] {
encountered[r.Table.Name] = true
tables = append(tables, r.Table)
}
relations = append(relations, r)
if !contains(relations, r) {
relations = append(relations, r)
}
}
}

Expand All @@ -61,3 +65,12 @@ func OutputTable(wr io.Writer, t *schema.Table) error {

return nil
}

func contains(rs []*schema.Relation, e *schema.Relation) bool {
for _, r := range rs {
if e == r {
return true
}
}
return false
}
14 changes: 7 additions & 7 deletions output/md/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ import (
"github.com/jessevdk/go-assets"
)

var _Assets43889384df1c6f74d764c29d91b9d5637eb46061 = "# {{ .Schema.Name }}\n\n## Tables\n{{ range $t := .Tables }}\n|{{ range $d := $t }} {{ $d | nl2br }} |{{ end }}\n{{- end }}\n\n{{ if .er -}}\n## Relations\n\n![er](schema.png)\n{{- end }}\n\n---\n\n> Generated by [tbls](https://github.com/k1LoW/tbls)"
var _Assetsac44302fb6150a621aa9d04a0350aac972bf7e18 = "# {{ .Table.Name }}\n\n## Description\n\n{{ .Table.Comment | nl2mdnl -}}\n{{ if .Table.Def }}\n<details>\n<summary><strong>Table Definition</strong></summary>\n\n```sql\n{{ .Table.Def }}\n```\n\n</details>\n{{ end }}\n\n## Columns\n{{ range $l := .Columns }}\n|{{ range $d := $l }} {{ $d | nl2br }} |{{ end }}\n{{- end }}\n\n{{ $len := len .Constraints }}{{ if ne $len 2 -}}\n## Constraints\n{{ range $l := .Constraints }}\n|{{ range $d := $l }} {{ $d | nl2br }} |{{ end }}\n{{- end }}\n{{- end }}\n\n{{ $len := len .Indexes -}}{{ if ne $len 2 -}}\n## Indexes\n{{ range $l := .Indexes }}\n|{{ range $d := $l }} {{ $d | nl2br }} |{{ end }}\n{{- end }}\n{{- end }}\n\n{{ $len := len .Triggers -}}{{ if ne $len 2 -}}\n## Triggers\n{{ range $l := .Triggers }}\n|{{ range $d := $l }} {{ $d | nl2br }} |{{ end }}\n{{- end }}\n{{- end }}\n\n{{ if .er -}}\n## Relations\n\n![er]({{ .Table.Name }}.png)\n{{- end }}\n\n---\n\n> Generated by [tbls](https://github.com/k1LoW/tbls)"
var _Assets43889384df1c6f74d764c29d91b9d5637eb46061 = "# {{ .Schema.Name }}\n\n## Tables\n{{ range $t := .Tables }}\n|{{ range $d := $t }} {{ $d | nl2br }} |{{ end }}\n{{- end }}\n\n{{ if .er -}}\n## Relations\n\n![er](schema.png)\n{{- end }}\n\n---\n\n> Generated by [tbls](https://github.com/k1LoW/tbls)"

// Assets returns go-assets FileSystem
var Assets = assets.NewFileSystem(map[string][]string{"/": []string{"index.md.tmpl", "table.md.tmpl"}}, map[string]*assets.File{
"/table.md.tmpl": &assets.File{
Path: "/table.md.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1532785399, 1532785399000000000),
Data: []byte(_Assetsac44302fb6150a621aa9d04a0350aac972bf7e18),
}, "/": &assets.File{
"/": &assets.File{
Path: "/",
FileMode: 0x800001ed,
Mtime: time.Unix(1532785399, 1532785399000000000),
Expand All @@ -26,4 +21,9 @@ var Assets = assets.NewFileSystem(map[string][]string{"/": []string{"index.md.tm
FileMode: 0x1a4,
Mtime: time.Unix(1532239511, 1532239511000000000),
Data: []byte(_Assets43889384df1c6f74d764c29d91b9d5637eb46061),
}, "/table.md.tmpl": &assets.File{
Path: "/table.md.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1532785399, 1532785399000000000),
Data: []byte(_Assetsac44302fb6150a621aa9d04a0350aac972bf7e18),
}}, "")
Binary file modified sample/adjust/comment_stars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/adjust/comments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mysql/comment_stars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mysql/comments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mysql8/comment_stars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mysql8/comments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/postgres/comment_stars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/postgres/comments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/sqlite/comment_stars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/sqlite/comments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b6b69ca

Please sign in to comment.