Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show table comments for related tables of View (#587) #590

Merged
merged 5 commits into from
Jun 4, 2024
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
14 changes: 8 additions & 6 deletions output/md/md.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,20 +701,22 @@ func (m *Md) makeTableTemplateData(t *schema.Table) map[string]interface{} {
}

// Referenced Tables
referencedTables := []string{}
hasReferencedTableWithLabels := false
for _, rt := range t.ReferencedTables {
if rt.External {
referencedTables = append(referencedTables, rt.Name)
continue
if len(rt.Labels) > 0 {
hasReferencedTableWithLabels = true
break
}
referencedTables = append(referencedTables, fmt.Sprintf("[%s](%s%s.md)", rt.Name, m.config.BaseUrl, mdurl.Encode(rt.Name)))
}

referencedTables := m.tablesData(t.ReferencedTables, number, adjust, showOnlyFirstParagraph, hasReferencedTableWithLabels)

if number {
columnsData = m.addNumberToTable(columnsData)
constraintsData = m.addNumberToTable(constraintsData)
indexesData = m.addNumberToTable(indexesData)
triggersData = m.addNumberToTable(triggersData)
referencedTables = m.addNumberToTable(referencedTables)
}

if adjust {
Expand All @@ -725,7 +727,7 @@ func (m *Md) makeTableTemplateData(t *schema.Table) map[string]interface{} {
"Constraints": adjustTable(constraintsData),
"Indexes": adjustTable(indexesData),
"Triggers": adjustTable(triggersData),
"ReferencedTables": referencedTables,
"ReferencedTables": adjustTable(referencedTables),
}
}

Expand Down
3 changes: 2 additions & 1 deletion output/md/md_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var tests = []struct {
{"mermaid a.md", "mermaid", false, false, false, false, "b", "a.md", "md_test_a.md.mermaid"},
{"showOnlyFirstParagraph README.md", "png", false, false, false, true, "b", "README.md", "md_test_README.md.first_para"},
{"showOnlyFirstParagraph a.md", "png", false, false, false, true, "b", "a.md", "md_test_a.md.first_para"},

{"view.md", "png", false, false, true, false, "b", "view.md", "md_test_view.md"},
{"viewpoint-1.md", "png", false, false, false, false, "b", "viewpoint-1.md", "md_test_viewpoint-1.md"},
{"viewpoint-2.md", "png", false, false, false, false, "b", "viewpoint-2.md", "md_test_viewpoint-2.md"},
{"viewpoint-1.md", "mermaid", false, false, false, false, "b", "viewpoint-1.md", "md_test_viewpoint-1.md.mermaid"},
Expand All @@ -49,6 +49,7 @@ var testsTemplate = []struct {
}{
{"README.md", false, false, true, false, "README.md", "md_template_test_README.md"},
{"a.md", false, false, true, false, "a.md", "md_template_test_a.md"},
{"view.md", false, false, true, false, "view.md", "md_template_test_view.md"},
{"--adjust option", true, false, true, false, "README.md", "md_template_test_README.md.adjust"},
{"number", false, true, true, false, "README.md", "md_template_test_README.md.number"},
{"showOnlyFirstParagraph", false, true, true, true, "README.md", "md_template_test_README.md.first_para"},
Expand Down
11 changes: 7 additions & 4 deletions output/md/templates/table.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
```

</details>
{{- end }}{{ $len := len .ReferencedTables }}{{ if ne $len 0 }}

## {{ "Referenced Tables" | lookup }}
{{ range $rt := .ReferencedTables }}
- {{ $rt }}{{ end }}
{{- end }}
{{- if ne (len .Table.Labels) 0 }}

Expand All @@ -34,6 +30,13 @@
|{{ range $d := $l }} {{ $d | nl2br }} |{{ end }}
{{- end }}

{{ $len := len .ReferencedTables }}{{ if ne $len 2 -}}
## {{ "Referenced Tables" | lookup }}
{{ range $l := .ReferencedTables }}
|{{ range $d := $l }} {{ $d | nl2br }} |{{ end }}
{{- end }}

{{ end -}}
{{ $len := len .Viewpoints }}{{ if ne $len 2 -}}
## {{ "Viewpoints" | lookup }}
{{ range $l := .Viewpoints }}
Expand Down
14 changes: 8 additions & 6 deletions sample/adjust/public.post_comment_stars.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ CREATE MATERIALIZED VIEW post_comment_stars AS (

</details>

## Referenced Tables

- [public.comments](public.comments.md)
- [public.comment_stars](public.comment_stars.md)
- [public.users](public.users.md)

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
Expand All @@ -37,6 +31,14 @@ CREATE MATERIALIZED VIEW post_comment_stars AS (
| created | timestamp without time zone | | true | | | |
| updated | timestamp without time zone | | true | | | |

## Referenced Tables

| Name | Columns | Comment | Type |
| ----------------------------------------------- | ------- | ------------------------------------------ | ---------- |
| [public.comments](public.comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [public.comment_stars](public.comment_stars.md) | 6 | | BASE TABLE |
| [public.users](public.users.md) | 6 | Users table | BASE TABLE |

## Relations

![er](public.post_comment_stars.svg)
Expand Down
14 changes: 8 additions & 6 deletions sample/adjust/public.post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ CREATE VIEW post_comments AS (

</details>

## Referenced Tables

- [public.posts](public.posts.md)
- [public.comments](public.comments.md)
- [public.users](public.users.md)

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
Expand All @@ -43,6 +37,14 @@ CREATE VIEW post_comments AS (
| created | timestamp without time zone | | true | | | comments.created |
| updated | timestamp without time zone | | true | | | comments.updated |

## Referenced Tables

| Name | Columns | Comment | Type |
| ------------------------------------- | ------- | ------------------------------------------ | ---------- |
| [public.posts](public.posts.md) | 8 | Posts table | BASE TABLE |
| [public.comments](public.comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [public.users](public.users.md) | 6 | Users table | BASE TABLE |

## Relations

![er](public.post_comments.svg)
Expand Down
2 changes: 1 addition & 1 deletion sample/adjust/schema.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions sample/detect_relations/post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2

</details>

## Referenced Tables

- [posts](posts.md)
- [comments](comments.md)
- [users](users.md)

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
Expand All @@ -31,6 +25,14 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2
| created | datetime | | true | | | comments.created |
| updated | datetime | | true | | | comments.updated |

## Referenced Tables

| Name | Columns | Comment | Type | Labels |
| ---- | ------- | ------- | ---- | ------ |
| [posts](posts.md) | 7 | Posts table | BASE TABLE | `green` `red` `blue` |
| [comments](comments.md) | 6 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE | |
| [users](users.md) | 6 | Users table | BASE TABLE | |

## Relations

![er](post_comments.svg)
Expand Down
2 changes: 1 addition & 1 deletion sample/detect_relations/schema.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions sample/detect_relations_singular/post_comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ CREATE VIEW post_comment AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`

</details>

## Referenced Tables

- [post](post.md)
- [comment](comment.md)
- [user](user.md)

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
Expand All @@ -31,6 +25,14 @@ CREATE VIEW post_comment AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2`
| created | datetime | | true | | | comment.created |
| updated | datetime | | true | | | comment.updated |

## Referenced Tables

| Name | Columns | Comment | Type | Labels |
| ---- | ------- | ------- | ---- | ------ |
| [post](post.md) | 7 | Post table | BASE TABLE | `green` `red` `blue` |
| [comment](comment.md) | 6 | Comment<br>Multi-line<br>table<br>comment | BASE TABLE | |
| [user](user.md) | 6 | User table | BASE TABLE | |

## Relations

![er](post_comment.svg)
Expand Down
2 changes: 1 addition & 1 deletion sample/detect_relations_singular/schema.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions sample/dict/post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2

</details>

## Referenced Tables

- [posts](posts.md)
- [comments](comments.md)
- [users](users.md)

## カラム一覧

| 名前 | タイプ | デフォルト値 | Nullable | 子テーブル | 親テーブル | コメント |
Expand All @@ -31,6 +25,14 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2
| created | datetime | | true | | | |
| updated | datetime | | true | | | |

## Referenced Tables

| 名前 | カラム一覧 | コメント | タイプ |
| ------------------------- | --------------- | ---------------------------------------------- | ------------- |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
| [comments](comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [users](users.md) | 6 | Users table | BASE TABLE |

## ER図

![er](post_comments.svg)
Expand Down
2 changes: 1 addition & 1 deletion sample/dict/schema.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions sample/exclude/post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2

</details>

## Referenced Tables

- [posts](posts.md)
- [comments](comments.md)
- [users](users.md)

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
Expand All @@ -31,6 +25,14 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2
| created | datetime | | true | | | comments.created |
| updated | datetime | | true | | | comments.updated |

## Referenced Tables

| Name | Columns | Comment | Type |
| ---- | ------- | ------- | ---- |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
| [comments](comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [users](users.md) | 6 | Users table | BASE TABLE |

## Relations

![er](post_comments.svg)
Expand Down
2 changes: 1 addition & 1 deletion sample/exclude/schema.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions sample/font/post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2

</details>

## Referenced Tables

- [posts](posts.md)
- [comments](comments.md)
- [users](users.md)

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
Expand All @@ -31,6 +25,14 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2
| created | datetime | | true | | | comments.created |
| updated | datetime | | true | | | comments.updated |

## Referenced Tables

| Name | Columns | Comment | Type |
| ---- | ------- | ------- | ---- |
| [posts](posts.md) | 7 | エントリ | BASE TABLE |
| [comments](comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [users](users.md) | 6 | Users table | BASE TABLE |

## Relations

![er](post_comments.png)
Expand Down
2 changes: 1 addition & 1 deletion sample/font/schema.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions sample/hide/post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2

</details>

## Referenced Tables

- [posts](posts.md)
- [comments](comments.md)
- [users](users.md)

## Columns

| Name | Type | Default | Nullable | Comment |
Expand All @@ -31,6 +25,14 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2
| created | datetime | | true | comments.created |
| updated | datetime | | true | comments.updated |

## Referenced Tables

| Name | Columns | Comment | Type | Labels |
| ---- | ------- | ------- | ---- | ------ |
| [posts](posts.md) | 7 | Posts table | BASE TABLE | `green` `red` `blue` |
| [comments](comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE | |
| [users](users.md) | 6 | Users table | BASE TABLE | |

## Relations

![er](post_comments.svg)
Expand Down
2 changes: 1 addition & 1 deletion sample/hide/schema.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions sample/hide_not_related_column/post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2

</details>

## Referenced Tables

- [posts](posts.md)
- [comments](comments.md)
- [users](users.md)

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
Expand All @@ -31,6 +25,14 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2
| created | datetime | | true | | | comments.created |
| updated | datetime | | true | | | comments.updated |

## Referenced Tables

| Name | Columns | Comment | Type | Labels |
| ---- | ------- | ------- | ---- | ------ |
| [posts](posts.md) | 7 | Posts table | BASE TABLE | `green` `red` `blue` |
| [comments](comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE | |
| [users](users.md) | 6 | Users table | BASE TABLE | |

## Relations

![er](post_comments.svg)
Expand Down
2 changes: 1 addition & 1 deletion sample/hide_not_related_column/schema.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions sample/mariadb/post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u

</details>

## Referenced Tables

- [posts](posts.md)
- [comments](comments.md)
- [users](users.md)

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
Expand All @@ -31,6 +25,14 @@ CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u
| created | datetime | | true | | | comments.created |
| updated | datetime | NULL | true | | | comments.updated |

## Referenced Tables

| Name | Columns | Comment | Type | Labels |
| ---- | ------- | ------- | ---- | ------ |
| [posts](posts.md) | 7 | Posts table | BASE TABLE | `green` `red` `blue` |
| [comments](comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE | |
| [users](users.md) | 6 | Users table | BASE TABLE | |

## Relations

![er](post_comments.svg)
Expand Down
2 changes: 1 addition & 1 deletion sample/mariadb/schema.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions sample/mermaid/post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2

</details>

## Referenced Tables

- [posts](posts.md)
- [comments](comments.md)
- [users](users.md)

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
Expand All @@ -31,6 +25,14 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2
| created | datetime | | true | | | comments.created |
| updated | datetime | | true | | | comments.updated |

## Referenced Tables

| Name | Columns | Comment | Type | Labels |
| ---- | ------- | ------- | ---- | ------ |
| [posts](posts.md) | 7 | Posts table | BASE TABLE | `green` `red` `blue` |
| [comments](comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE | |
| [users](users.md) | 6 | Users table | BASE TABLE | |

## Relations

```mermaid
Expand Down
2 changes: 1 addition & 1 deletion sample/mermaid/schema.json

Large diffs are not rendered by default.

Loading
Loading