Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into escape-html
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed May 30, 2018
2 parents 978603c + 9448176 commit 6320806
Show file tree
Hide file tree
Showing 23 changed files with 16 additions and 8 deletions.
10 changes: 5 additions & 5 deletions output/dot/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import (
"github.com/jessevdk/go-assets"
)

var _Assets21532ae17ad95976ac467eeaeab81f2bb1d537e4 = "digraph {{ .Schema.Name }} {\n // Config\n graph [rankdir=TB, layout=dot, fontname=\"Arial\"];\n node [shape=record, fontsize=14, margin=0.6, fontname=\"Arial\"];\n edge [fontsize=10, labelfloat=false, splines=none, fontname=\"Arial\"];\n\n // Tables\n {{- range $i, $t := .Schema.Tables }}\n {{ $t.Name }} [shape=none, label=<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\" cellpadding=\"6\">\n <tr><td bgcolor=\"#EFEFEF\"><font face=\"Arial Bold\" point-size=\"18\">{{ $t.Name | html }}</font> <font color=\"#666666\">[{{ $t.Type | html }}]</font></td></tr>\n {{- range $ii, $c := $t.Columns }}\n <tr><td port=\"{{ $c.Name | html }}\" align=\"left\">{{ $c.Name | html }} <font color=\"#666666\">[{{ $c.Type | html }}]</font></td></tr>\n {{- end }}\n </table>>];\n {{- end }}\n\n // Relations\n {{- range $j, $r := .Schema.Relations }}\n {{ $r.Table.Name }}:{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> {{ $r.ParentTable.Name }}:{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, taillabel=<<table cellpadding=\"5\" border=\"0\" cellborder=\"0\"><tr><td>{{ $r.Def | html }}</td></tr></table>>];\n {{- end }}\n}\n"
var _Assets5bd148e6149bb9adcdddfcf8cc46d6e3047dbe26 = "digraph {{ .Table.Name }} {\n // Config\n graph [rankdir=TB, layout=dot, fontname=\"Arial\"];\n node [shape=record, fontsize=14, margin=0.6, fontname=\"Arial\"];\n edge [fontsize=10, labelfloat=false, splines=none, fontname=\"Arial\"];\n\n // Tables\n {{ .Table.Name }} [shape=none, label=<<table border=\"3\" cellborder=\"1\" cellspacing=\"0\" cellpadding=\"6\">\n <tr><td bgcolor=\"#EFEFEF\"><font face=\"Arial Bold\" point-size=\"18\">{{ .Table.Name | html }}</font> <font color=\"#666666\">[{{ .Table.Type | html }}]</font></td></tr>\n {{- range $ii, $c := .Table.Columns }}\n <tr><td port=\"{{ $c.Name | html }}\" align=\"left\">{{ $c.Name | html }} <font color=\"#666666\">[{{ $c.Type }}]</font></td></tr>\n {{- end }}\n </table>>];\n {{- range $i, $t := .Tables }}\n {{ $t.Name }} [shape=none, label=<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\" cellpadding=\"6\">\n <tr><td bgcolor=\"#EFEFEF\"><font face=\"Arial Bold\" point-size=\"18\">{{ $t.Name | html }}</font> <font color=\"#666666\">[{{ $t.Type | html }}]</font></td></tr>\n {{- range $ii, $c := $t.Columns }}\n <tr><td port=\"{{ $c.Name | html }}\" align=\"left\">{{ $c.Name | html }} <font color=\"#666666\">[{{ $c.Type | html }}]</font></td></tr>\n {{- end }}\n </table>>];\n {{- end }}\n\n // Relations\n {{- range $i, $r := .Relations }}\n {{ $r.Table.Name }}:{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> {{ $r.ParentTable.Name }}:{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, taillabel=<<table cellpadding=\"5\" border=\"0\" cellborder=\"0\"><tr><td>{{ $r.Def | html }}</td></tr></table>>];\n {{- end }}\n}\n"
var _Assets21532ae17ad95976ac467eeaeab81f2bb1d537e4 = "digraph {{ .Schema.Name }} {\n // Config\n graph [rankdir=TB, layout=dot, fontname=\"Arial\"];\n node [shape=record, fontsize=14, margin=0.6, fontname=\"Arial\"];\n edge [fontsize=10, labelfloat=false, splines=none, fontname=\"Arial\"];\n\n // Tables\n {{- range $i, $t := .Schema.Tables }}\n {{ $t.Name }} [shape=none, label=<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\" cellpadding=\"6\">\n <tr><td bgcolor=\"#EFEFEF\"><font face=\"Arial Bold\" point-size=\"18\">{{ $t.Name | html }}</font> <font color=\"#666666\">[{{ $t.Type | html }}]</font></td></tr>\n {{- range $ii, $c := $t.Columns }}\n <tr><td port=\"{{ $c.Name | html }}\" align=\"left\">{{ $c.Name | html }} <font color=\"#666666\">[{{ $c.Type | html }}]</font></td></tr>\n {{- end }}\n </table>>];\n {{- end }}\n\n // Relations\n {{- range $j, $r := .Schema.Relations }}\n {{ $r.Table.Name }}:{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> {{ $r.ParentTable.Name }}:{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, {{ if $r.IsAdditional }}style=\"dashed\",{{ end }} taillabel=<<table cellpadding=\"5\" border=\"0\" cellborder=\"0\"><tr><td>{{ $r.Def | html }}</td></tr></table>>];\n {{- end }}\n}\n"
var _Assets5bd148e6149bb9adcdddfcf8cc46d6e3047dbe26 = "digraph {{ .Table.Name }} {\n // Config\n graph [rankdir=TB, layout=dot, fontname=\"Arial\"];\n node [shape=record, fontsize=14, margin=0.6, fontname=\"Arial\"];\n edge [fontsize=10, labelfloat=false, splines=none, fontname=\"Arial\"];\n\n // Tables\n {{ .Table.Name }} [shape=none, label=<<table border=\"3\" cellborder=\"1\" cellspacing=\"0\" cellpadding=\"6\">\n <tr><td bgcolor=\"#EFEFEF\"><font face=\"Arial Bold\" point-size=\"18\">{{ .Table.Name | html }}</font> <font color=\"#666666\">[{{ .Table.Type | html }}]</font></td></tr>\n {{- range $ii, $c := .Table.Columns }}\n <tr><td port=\"{{ $c.Name | html }}\" align=\"left\">{{ $c.Name | html }} <font color=\"#666666\">[{{ $c.Type }}]</font></td></tr>\n {{- end }}\n </table>>];\n {{- range $i, $t := .Tables }}\n {{ $t.Name }} [shape=none, label=<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\" cellpadding=\"6\">\n <tr><td bgcolor=\"#EFEFEF\"><font face=\"Arial Bold\" point-size=\"18\">{{ $t.Name | html }}</font> <font color=\"#666666\">[{{ $t.Type | html }}]</font></td></tr>\n {{- range $ii, $c := $t.Columns }}\n <tr><td port=\"{{ $c.Name | html }}\" align=\"left\">{{ $c.Name | html }} <font color=\"#666666\">[{{ $c.Type | html }}]</font></td></tr>\n {{- end }}\n </table>>];\n {{- end }}\n\n // Relations\n {{- range $i, $r := .Relations }}\n {{ $r.Table.Name }}:{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> {{ $r.ParentTable.Name }}:{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, {{ if $r.IsAdditional }}style =\"dashed\",{{ end }} taillabel=<<table cellpadding=\"5\" border=\"0\" cellborder=\"0\"><tr><td>{{ $r.Def | html }}</td></tr></table>>];\n {{- end }}\n}\n"

// Assets returns go-assets FileSystem
var Assets = assets.NewFileSystem(map[string][]string{"/": []string{"schema.dot.tmpl", "table.dot.tmpl"}}, map[string]*assets.File{
"/": &assets.File{
Path: "/",
FileMode: 0x800001ed,
Mtime: time.Unix(1527688034, 1527688034000000000),
Mtime: time.Unix(1527688259, 1527688259000000000),
Data: nil,
}, "/schema.dot.tmpl": &assets.File{
Path: "/schema.dot.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1527687951, 1527687951000000000),
Mtime: time.Unix(1527688259, 1527688259000000000),
Data: []byte(_Assets21532ae17ad95976ac467eeaeab81f2bb1d537e4),
}, "/table.dot.tmpl": &assets.File{
Path: "/table.dot.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1527688034, 1527688034000000000),
Mtime: time.Unix(1527688250, 1527688250000000000),
Data: []byte(_Assets5bd148e6149bb9adcdddfcf8cc46d6e3047dbe26),
}}, "")
2 changes: 1 addition & 1 deletion output/dot/templates/schema.dot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ digraph {{ .Schema.Name }} {

// Relations
{{- range $j, $r := .Schema.Relations }}
{{ $r.Table.Name }}:{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> {{ $r.ParentTable.Name }}:{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, taillabel=<<table cellpadding="5" border="0" cellborder="0"><tr><td>{{ $r.Def | html }}</td></tr></table>>];
{{ $r.Table.Name }}:{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> {{ $r.ParentTable.Name }}:{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, {{ if $r.IsAdditional }}style="dashed",{{ end }} taillabel=<<table cellpadding="5" border="0" cellborder="0"><tr><td>{{ $r.Def | html }}</td></tr></table>>];
{{- end }}
}
2 changes: 1 addition & 1 deletion output/dot/templates/table.dot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ digraph {{ .Table.Name }} {

// Relations
{{- range $i, $r := .Relations }}
{{ $r.Table.Name }}:{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> {{ $r.ParentTable.Name }}:{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, taillabel=<<table cellpadding="5" border="0" cellborder="0"><tr><td>{{ $r.Def | html }}</td></tr></table>>];
{{ $r.Table.Name }}:{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> {{ $r.ParentTable.Name }}:{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, {{ if $r.IsAdditional }}style ="dashed",{{ end }} taillabel=<<table cellpadding="5" border="0" cellborder="0"><tr><td>{{ $r.Def | html }}</td></tr></table>>];
{{- end }}
}
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/mysql/logs.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/posts.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/schema.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/users.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/mysql8/logs.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/posts.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/schema.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/users.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/postgres/logs.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/posts.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/schema.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/users.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Relation struct {
ParentTable *Table
ParentColumns []*Column
Def string
IsAdditional bool
}

// Schema is the struct for database schema
Expand All @@ -70,6 +71,7 @@ type AdditionalRelation struct {
Columns []string `yaml:"columns"`
ParentTable string `yaml:"parentTable"`
ParentColumns []string `yaml:"parentColumns"`
Def string `yaml:"def"`
}

// FindTableByName find table by table name
Expand Down Expand Up @@ -142,7 +144,12 @@ func (s *Schema) LoadAdditionalRelations(path string) error {

for _, r := range data.Relations {
relation := &Relation{
Def: "Additional Relation",
IsAdditional: true,
}
if r.Def != "" {
relation.Def = r.Def
} else {
relation.Def = "Additional Relation"
}
relation.Table, err = s.FindTableByName(r.Table)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions test/relations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ relations:
parentTable: users
parentColumns:
- id
def: logs->users
-
table: logs
columns:
Expand Down

0 comments on commit 6320806

Please # to comment.