Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,36 @@
"type": "TypeString"
}
],
"relations": []
"relations": [
{
"name": "relation_relation_table",
"description": "Description for relational table's relation",
"columns": [
{
"name": "_cq_source_name",
"type": "TypeString"
},
{
"name": "_cq_sync_time",
"type": "TypeTimestamp"
},
{
"name": "_cq_id",
"type": "TypeUUID",
"is_primary_key": true
},
{
"name": "_cq_parent_id",
"type": "TypeUUID"
},
{
"name": "string_col",
"type": "TypeString"
}
],
"relations": []
}
]
},
{
"name": "relation_table2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Source Plugin: test
## Tables
| Name |
| ------------- |
| [test_table](test_table.md) |
| ↳ [relation_table](relation_table.md) |
| ↳ [relation_table2](relation_table2.md) |
- [test_table](test_table.md)
- [relation_table](relation_table.md)
- [relation_relation_table](relation_relation_table.md)
- [relation_table2](relation_table2.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Table: relation_relation_table

Description for relational table's relation

The primary key for this table is **_cq_id**.

## Relations
This table depends on [relation_table](relation_table.md).


## Columns
| Name | Type |
| ------------- | ------------- |
|_cq_source_name|String|
|_cq_sync_time|Timestamp|
|_cq_id (PK)|UUID|
|_cq_parent_id|UUID|
|string_col|String|
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ The primary key for this table is **_cq_id**.
## Relations
This table depends on [test_table](test_table.md).

The following tables depend on relation_table:
- [relation_relation_table](relation_relation_table.md)

## Columns
| Name | Type |
| ------------- | ------------- |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Description for test table
The composite primary key for this table is (**id_col**, **id_col2**).

## Relations

The following tables depend on test_table:
- [relation_table](relation_table.md)
- [relation_table2](relation_table2.md)
Expand Down
14 changes: 13 additions & 1 deletion plugins/source_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func (p *SourcePlugin) renderTablesAsMarkdown(dir string) error {
return err
}
}
t, err := template.New("all_tables.md.go.tpl").ParseFS(templatesFS, "templates/all_tables.md.go.tpl")
t, err := template.New("all_tables.md.go.tpl").Funcs(template.FuncMap{
"indentToDepth": indentToDepth,
}).ParseFS(templatesFS, "templates/all_tables*.md.go.tpl")
if err != nil {
return fmt.Errorf("failed to parse template for README.md: %v", err)
}
Expand Down Expand Up @@ -136,3 +138,13 @@ func renderTable(table *schema.Table, dir string) error {
func formatType(v schema.ValueType) string {
return strings.TrimPrefix(v.String(), "Type")
}

func indentToDepth(table *schema.Table) string {
s := ""
t := table
for t.Parent != nil {
s += " "
t = t.Parent
}
return s
}
14 changes: 13 additions & 1 deletion plugins/source_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ var testTables = []*schema.Table{
Type: schema.TypeString,
},
},
Relations: []*schema.Table{
{
Name: "relation_relation_table",
Description: "Description for relational table's relation",
Columns: []schema.Column{
{
Name: "string_col",
Type: schema.TypeString,
},
},
},
},
},
{
Name: "relation_table2",
Expand All @@ -68,7 +80,7 @@ func TestGenerateSourcePluginDocs(t *testing.T) {
t.Fatalf("unexpected error calling GenerateSourcePluginDocs: %v", err)
}

expectFiles := []string{"test_table.md", "relation_table.md", "README.md"}
expectFiles := []string{"test_table.md", "relation_table.md", "relation_relation_table.md", "README.md"}
for _, exp := range expectFiles {
t.Run(exp, func(t *testing.T) {
output := path.Join(tmpdir, exp)
Expand Down
7 changes: 1 addition & 6 deletions plugins/templates/all_tables.md.go.tpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Source Plugin: {{.Name}}
## Tables
| Name |
| ------------- |
{{- range $table := $.Tables }}
| [{{$table.Name}}]({{$table.Name}}.md) |
{{- range $index, $rel := $table.Relations}}
| ↳ [{{$rel.Name}}]({{$rel.Name}}.md) |
{{- end}}
{{- template "all_tables_entry.md.go.tpl" $table}}
{{- end }}
5 changes: 5 additions & 0 deletions plugins/templates/all_tables_entry.md.go.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

{{. | indentToDepth}}- [{{.Name}}]({{.Name}}.md)
{{- range $index, $rel := .Relations}}
{{- template "all_tables_entry.md.go.tpl" $rel}}
{{- end}}
3 changes: 1 addition & 2 deletions plugins/templates/table.md.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ The composite primary key for this table is ({{ range $index, $pk := $.PrimaryKe
{{- if $.Parent }}
This table depends on [{{ $.Parent.Name }}]({{ $.Parent.Name }}.md).
{{- end}}

{{- if $.Relations }}
{{ if $.Relations }}
The following tables depend on {{.Name}}:
{{- range $rel := $.Relations }}
- [{{ $rel.Name }}]({{ $rel.Name }}.md)
Expand Down