Skip to content

Commit 379d38c

Browse files
authored
feat: Add PK information to generated docs (#136)
This is important information to have, as it will tell users what columns will be used for replacing rows in overwrite mode, as well as inform on good candidates for performing relational joins.
1 parent 19447ec commit 379d38c

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11

22
# Table: relation_table
33
Description for relational table
4+
5+
The primary key for this table is **_cq_id**.
6+
47
## Columns
58
| Name | Type |
69
| ------------- | ------------- |
710
|string_col|String|
8-
|_cq_id|UUID|
11+
|_cq_id (PK)|UUID|
912
|_cq_fetch_time|Timestamp|
1013

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11

22
# Table: test_table
33
Description for test table
4+
5+
The composite primary key for this table is (**id_col**, **id_col2**).
6+
47
## Columns
58
| Name | Type |
69
| ------------- | ------------- |
710
|int_col|Int|
11+
|id_col (PK)|Int|
12+
|id_col2 (PK)|Int|
813
|_cq_id|UUID|
914
|_cq_fetch_time|Timestamp|
1015

plugins/source_docs.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@ import (
1313
const tableTmpl = `
1414
# Table: {{.Name}}
1515
{{ $.Description }}
16+
{{ $length := len $.PrimaryKeys -}}
17+
{{ if eq $length 1 }}
18+
The primary key for this table is **{{ index $.PrimaryKeys 0 }}**.
19+
{{ else }}
20+
The composite primary key for this table is ({{ range $index, $pk := $.PrimaryKeys -}}
21+
{{if $index }}, {{end -}}
22+
**{{$pk}}**
23+
{{- end -}}).
24+
{{ end }}
1625
## Columns
1726
| Name | Type |
1827
| ------------- | ------------- |
1928
{{- range $column := $.Columns }}
20-
|{{$column.Name}}|{{$column.Type | formatType}}|
29+
|{{$column.Name}}{{if $column.CreationOptions.PrimaryKey}} (PK){{end}}|{{$column.Type | formatType}}|
2130
{{- end }}
2231
`
2332

plugins/source_docs_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ var testTables = []*schema.Table{
1919
Name: "int_col",
2020
Type: schema.TypeInt,
2121
},
22+
{
23+
Name: "id_col",
24+
Type: schema.TypeInt,
25+
CreationOptions: schema.ColumnCreationOptions{PrimaryKey: true},
26+
},
27+
{
28+
Name: "id_col2",
29+
Type: schema.TypeInt,
30+
CreationOptions: schema.ColumnCreationOptions{PrimaryKey: true},
31+
},
2232
},
2333
Relations: []*schema.Table{
2434
{

0 commit comments

Comments
 (0)