Skip to content

Commit bea1fb2

Browse files
authored
fix(table-diff): Improve primary keys comments (#5800)
<!-- 🎉 Thank you for making CloudQuery awesome by submitting a PR 🎉 --> #### Summary This improves the table diff comment for primary keys. From the current comment: ![image](https://user-images.githubusercontent.com/26760571/208428236-52ae891b-53b1-430b-b3b4-29ff55457030.png) It can be understood that the column was removed, but actually the primary key was removed <!-- Use the following steps to ensure your PR is ready to be reviewed - [ ] Read the [contribution guidelines](../blob/main/CONTRIBUTING.md) 🧑‍🎓 - [ ] Test locally on your own infrastructure - [ ] Run `go fmt` to format your code 🖊 - [ ] Lint your changes via `golangci-lint run` 🚨 (install golangci-lint [here](https://golangci-lint.run/usage/install/#local-installation)) - [ ] Update or add tests 🧪 - [ ] Ensure the status checks below are successful ✅ --->
1 parent 3bdb218 commit bea1fb2

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

scripts/table_diff/changes/changes.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ func getColumnChanges(file *gitdiff.File, table string) (changes []change) {
8484

8585
if addedColumn.pk && !deletedColumn.pk {
8686
changes = append(changes, change{
87-
Text: fmt.Sprintf("Table %s: column primary key %s added", backtickStrings(table, deletedName)...),
87+
Text: fmt.Sprintf("Table %s: primary key constraint added to column %s", backtickStrings(table, deletedName)...),
8888
Breaking: false,
8989
})
9090
}
9191

9292
if !addedColumn.pk && deletedColumn.pk {
9393
changes = append(changes, change{
94-
Text: fmt.Sprintf("Table %s: column primary key %s removed", backtickStrings(table, deletedName)...),
94+
Text: fmt.Sprintf("Table %s: primary key constraint removed from column %s", backtickStrings(table, deletedName)...),
9595
Breaking: false,
9696
})
9797
}
@@ -104,8 +104,12 @@ func getColumnChanges(file *gitdiff.File, table string) (changes []change) {
104104
}
105105
for addedName, addedColumn := range addedColumns {
106106
if _, ok := deletedColumns[addedName]; !ok {
107+
name := addedName
108+
if addedColumn.pk {
109+
name = fmt.Sprintf("%s (PK)", name)
110+
}
107111
changes = append(changes, change{
108-
Text: fmt.Sprintf("Table %s: column added with name %s and type %s", backtickStrings(table, addedName, addedColumn.dataType)...),
112+
Text: fmt.Sprintf("Table %s: column added with name %s and type %s", backtickStrings(table, name, addedColumn.dataType)...),
109113
Breaking: false,
110114
})
111115
}

scripts/table_diff/changes/changes_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ func Test_getChanges(t *testing.T) {
166166
diffDataFile: "testdata/pr_5636_diff.txt",
167167
wantChanges: []change{
168168
{
169-
Text: "Table `gcp_resourcemanager_projects`: column primary key `_cq_id` removed",
169+
Text: "Table `gcp_resourcemanager_projects`: primary key constraint added to column `name`",
170170
Breaking: false,
171171
},
172172
{
173-
Text: "Table `gcp_resourcemanager_projects`: column primary key `name` added",
173+
Text: "Table `gcp_resourcemanager_projects`: primary key constraint added to column `project_id`",
174174
Breaking: false,
175175
},
176176
{
177-
Text: "Table `gcp_resourcemanager_projects`: column primary key `project_id` added",
177+
Text: "Table `gcp_resourcemanager_projects`: primary key constraint removed from column `_cq_id`",
178178
Breaking: false,
179179
},
180180
},

0 commit comments

Comments
 (0)