@startuml
{{ $sc := .showComment -}}
{{- $sd := .showDef -}}
!define table(name, desc) entity name as "desc" << (T,#5DBCD2) >>
!define view(name, desc) entity name as "desc" << (V,#C6EDDB) >>
!define column(name, type, desc) name <font color="#666666">[type]</font><font color="#333333">desc</font>
hide methods
hide stereotypes

skinparam class {
  BackgroundColor White
  BorderColor #6E6E6E
  ArrowColor #6E6E6E
}

' tables
{{- range $i, $t := .Schema.Tables }}
{{- if ne $t.Type "VIEW" }}
table("{{ $t.Name }}", "{{ $t.Name }}{{ if $sc }}{{ if ne $t.Comment "" }}\n{{ $t.Comment | html | escape_nl }}{{ end }}{{ end }}") {
{{- else }}
view("{{ $t.Name }}", "{{ $t.Name }}{{ if $sc }}{{ if ne $t.Comment "" }}\n{{ $t.Comment | html | escape_nl }}{{ end }}{{ end }}") {
{{- end }}
{{- range $ii, $c := $t.Columns }}
  {{- if $c.HideForER }}{{ continue }}{{ end }}
  column("{{ if $c.PK}}+ {{ end }}{{ if $c.FK }}# {{ end }}{{ $c.Name | html }}", "{{ $c.Type | html }}", "{{ if $sc }}{{ if ne $c.Comment "" }} {{ $c.Comment | html | nl2space }}{{ end }}{{ end }}")
{{- end }}
}
{{- end }}

' relations
{{- range $j, $r := .Schema.Relations }}
{{- if $r.HideForER }}{{ continue }}{{ end }}
"{{ $r.Table.Name }}" {{ $r.Cardinality | lcardi }}--{{ $r.ParentCardinality | rcardi }} "{{ $r.ParentTable.Name }}" : "{{ if $sd }}{{ $r.Def | html }}{{ end }}"
{{- end }}

@enduml
