diff --git a/output/dot/dot.go b/output/dot/dot.go index 9c086720..b2a34418 100644 --- a/output/dot/dot.go +++ b/output/dot/dot.go @@ -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) + } } } @@ -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 +} diff --git a/output/md/templates.go b/output/md/templates.go index 4640fc03..d78d92c8 100644 --- a/output/md/templates.go +++ b/output/md/templates.go @@ -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
\nTable Definition\n\n```sql\n{{ .Table.Def }}\n```\n\n
\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), @@ -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), }}, "") diff --git a/sample/adjust/comment_stars.png b/sample/adjust/comment_stars.png index c8cbc973..deb85b72 100644 Binary files a/sample/adjust/comment_stars.png and b/sample/adjust/comment_stars.png differ diff --git a/sample/adjust/comments.png b/sample/adjust/comments.png index d3004ba0..159e6c44 100644 Binary files a/sample/adjust/comments.png and b/sample/adjust/comments.png differ diff --git a/sample/mysql/comment_stars.png b/sample/mysql/comment_stars.png index 68c9e74b..420a6bf2 100644 Binary files a/sample/mysql/comment_stars.png and b/sample/mysql/comment_stars.png differ diff --git a/sample/mysql/comments.png b/sample/mysql/comments.png index 6bc733d8..2d2b1cd9 100644 Binary files a/sample/mysql/comments.png and b/sample/mysql/comments.png differ diff --git a/sample/mysql8/comment_stars.png b/sample/mysql8/comment_stars.png index 68c9e74b..420a6bf2 100644 Binary files a/sample/mysql8/comment_stars.png and b/sample/mysql8/comment_stars.png differ diff --git a/sample/mysql8/comments.png b/sample/mysql8/comments.png index 6bc733d8..2d2b1cd9 100644 Binary files a/sample/mysql8/comments.png and b/sample/mysql8/comments.png differ diff --git a/sample/postgres/comment_stars.png b/sample/postgres/comment_stars.png index c8cbc973..deb85b72 100644 Binary files a/sample/postgres/comment_stars.png and b/sample/postgres/comment_stars.png differ diff --git a/sample/postgres/comments.png b/sample/postgres/comments.png index d3004ba0..159e6c44 100644 Binary files a/sample/postgres/comments.png and b/sample/postgres/comments.png differ diff --git a/sample/sqlite/comment_stars.png b/sample/sqlite/comment_stars.png index 3b2316a2..61f6e38b 100644 Binary files a/sample/sqlite/comment_stars.png and b/sample/sqlite/comment_stars.png differ diff --git a/sample/sqlite/comments.png b/sample/sqlite/comments.png index 1d9482b3..555ef101 100644 Binary files a/sample/sqlite/comments.png and b/sample/sqlite/comments.png differ