From 99205d60eda57fa9d2d4be18dd6b9f7c773b81ba Mon Sep 17 00:00:00 2001 From: k1low Date: Fri, 6 Sep 2019 01:50:52 +0900 Subject: [PATCH 1/2] Remove duplicate relation links --- output/md/md.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/output/md/md.go b/output/md/md.go index 722f6ad1..5e818d8b 100644 --- a/output/md/md.go +++ b/output/md/md.go @@ -291,21 +291,21 @@ func makeTableTemplateData(t *schema.Table, adjust bool) map[string]interface{} []string{"----", "----", "-------", "--------", "--------", "-------", "-------"}, } for _, c := range t.Columns { - childRelations := []string{} + childRelations := map[string]string{} for _, r := range c.ChildRelations { - childRelations = append(childRelations, fmt.Sprintf("[%s](%s.md)", r.Table.Name, r.Table.Name)) + childRelations[r.Table.Name] = fmt.Sprintf("[%s](%s.md)", r.Table.Name, r.Table.Name) } - parentRelations := []string{} + parentRelations := map[string]string{} for _, r := range c.ParentRelations { - parentRelations = append(parentRelations, fmt.Sprintf("[%s](%s.md)", r.ParentTable.Name, r.ParentTable.Name)) + parentRelations[r.Table.Name] = fmt.Sprintf("[%s](%s.md)", r.ParentTable.Name, r.ParentTable.Name) } data := []string{ c.Name, c.Type, c.Default.String, fmt.Sprintf("%v", c.Nullable), - strings.Join(childRelations, " "), - strings.Join(parentRelations, " "), + stringMapJoin(childRelations, " "), + stringMapJoin(parentRelations, " "), c.Comment, } columnsData = append(columnsData, data) @@ -393,3 +393,11 @@ func adjustTable(data [][]string) [][]string { return data } + +func stringMapJoin(m map[string]string, sep string) string { + s := []string{} + for _, v := range m { + s = append(s, v) + } + return strings.Join(s, sep) +} From 36e5f244109c803c8ea4b407b83d3ca3cdb70654 Mon Sep 17 00:00:00 2001 From: k1low Date: Fri, 6 Sep 2019 02:04:41 +0900 Subject: [PATCH 2/2] Freeze order --- output/md/md.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/output/md/md.go b/output/md/md.go index 5e818d8b..55e0b09d 100644 --- a/output/md/md.go +++ b/output/md/md.go @@ -291,21 +291,31 @@ func makeTableTemplateData(t *schema.Table, adjust bool) map[string]interface{} []string{"----", "----", "-------", "--------", "--------", "-------", "-------"}, } for _, c := range t.Columns { - childRelations := map[string]string{} + childRelations := []string{} + cEncountered := map[string]bool{} for _, r := range c.ChildRelations { - childRelations[r.Table.Name] = fmt.Sprintf("[%s](%s.md)", r.Table.Name, r.Table.Name) + if _, ok := cEncountered[r.Table.Name]; ok { + continue + } + childRelations = append(childRelations, fmt.Sprintf("[%s](%s.md)", r.Table.Name, r.Table.Name)) + cEncountered[r.Table.Name] = true } - parentRelations := map[string]string{} + parentRelations := []string{} + pEncountered := map[string]bool{} for _, r := range c.ParentRelations { - parentRelations[r.Table.Name] = fmt.Sprintf("[%s](%s.md)", r.ParentTable.Name, r.ParentTable.Name) + if _, ok := pEncountered[r.ParentTable.Name]; ok { + continue + } + parentRelations = append(parentRelations, fmt.Sprintf("[%s](%s.md)", r.ParentTable.Name, r.ParentTable.Name)) + pEncountered[r.ParentTable.Name] = true } data := []string{ c.Name, c.Type, c.Default.String, fmt.Sprintf("%v", c.Nullable), - stringMapJoin(childRelations, " "), - stringMapJoin(parentRelations, " "), + strings.Join(childRelations, " "), + strings.Join(parentRelations, " "), c.Comment, } columnsData = append(columnsData, data) @@ -393,11 +403,3 @@ func adjustTable(data [][]string) [][]string { return data } - -func stringMapJoin(m map[string]string, sep string) string { - s := []string{} - for _, v := range m { - s = append(s, v) - } - return strings.Join(s, sep) -}