Skip to content

Commit 9eaedb7

Browse files
authored
chore(ci): Update table diff (#16415)
#### Summary This creates a special case where it will only log a message that says that all PKs have been replaced with `_cq_id` for a specific table...
1 parent e3c566c commit 9eaedb7

3 files changed

Lines changed: 62 additions & 7 deletions

File tree

scripts/table_diff/changes/changes.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import (
1515
var (
1616
columnRegex = regexp.MustCompile(`^\|(?P<name>.*)\|(?P<dataType>.*)\|`)
1717
pkRegex = regexp.MustCompile(`^The composite primary key for this table is \(([^)]+)\)\.`)
18+
19+
// There is a different message for single PKs
20+
singlePKRegex = regexp.MustCompile(`^The primary key for this table is ([^)]+)\.`)
1821
)
1922

2023
type change struct {
@@ -75,12 +78,17 @@ func parseColumnChange(line string) (name string, col column) {
7578
}
7679

7780
func parsePKChange(line string) (names []string) {
78-
match := pkRegex.FindStringSubmatch(line)
79-
if len(match) != 2 {
80-
return nil
81+
matchMulti := pkRegex.FindStringSubmatch(line)
82+
matchSingle := singlePKRegex.FindStringSubmatch(line)
83+
if len(matchMulti) == 2 {
84+
for _, part := range strings.Split(matchMulti[1], ", ") {
85+
names = append(names, strings.Trim(part, "*"))
86+
}
8187
}
82-
for _, part := range strings.Split(match[1], ", ") {
83-
names = append(names, strings.Trim(part, "*"))
88+
if len(matchSingle) == 2 {
89+
for _, part := range strings.Split(matchSingle[1], ", ") {
90+
names = append(names, strings.Trim(part, "*"))
91+
}
8492
}
8593
return
8694
}
@@ -141,14 +149,14 @@ func getColumnChanges(file *gitdiff.File, table string) (changes []change) {
141149
continue
142150
}
143151

144-
if added.pk() && !deleted.pk() {
152+
if added.pk() && !deleted.pk() && !(len(addedPK) == 1 && addedPK[0] == "_cq_id" && len(deletedPK) > 0) {
145153
changes = append(changes, change{
146154
Text: fmt.Sprintf("Table %s: primary key constraint added to column %s", backtickStrings(table, name)...),
147155
Breaking: true,
148156
})
149157
}
150158

151-
if !added.pk() && deleted.pk() {
159+
if !added.pk() && deleted.pk() && !(len(addedPK) == 1 && addedPK[0] == "_cq_id" && len(deletedPK) > 0) {
152160
changes = append(changes, change{
153161
Text: fmt.Sprintf("Table %s: primary key constraint removed from column %s", backtickStrings(table, name)...),
154162
Breaking: true,
@@ -216,6 +224,14 @@ func getColumnChanges(file *gitdiff.File, table string) (changes []change) {
216224
return chI.Text < chJ.Text
217225
}
218226
})
227+
228+
if len(addedPK) == 1 && addedPK[0] == "_cq_id" && len(deletedPK) > 0 {
229+
changes = append(changes, change{
230+
Text: fmt.Sprintf("Table %s: all existing primary key constraints have been removed and a primary key new constraint has been added to `_cq_id`", backtickStrings(table)...),
231+
Breaking: true,
232+
})
233+
}
234+
219235
return changes
220236
}
221237

scripts/table_diff/changes/changes_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ func Test_getChanges(t *testing.T) {
261261
},
262262
},
263263
},
264+
{
265+
name: "Special Case - don't report removal of pks, only end state",
266+
diffDataFile: "testdata/pr_100644_diff.txt",
267+
wantChanges: []change{
268+
{
269+
Text: "Table `aws_accessanalyzer_analyzers`: all existing primary key constraints have been removed and a primary key new constraint has been added to `_cq_id`",
270+
Breaking: true,
271+
},
272+
},
273+
},
264274
{
265275
name: "Should handle no backticks -> backticks",
266276
diffDataFile: "testdata/pr_11034_diff.txt",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
diff --git a/plugins/source/aws/docs/tables/aws_accessanalyzer_analyzers.md b/plugins/source/aws/docs/tables/aws_accessanalyzer_analyzers.md
2+
index 76569347f50fb9..88070ce42a78d0 100644
3+
--- a/plugins/source/aws/docs/tables/aws_accessanalyzer_analyzers.md
4+
+++ b/plugins/source/aws/docs/tables/aws_accessanalyzer_analyzers.md
5+
@@ -4,8 +4,8 @@ This table shows data for AWS Identity and Access Management (IAM) Access Analyz
6+
7+
https://docs.aws.amazon.com/access-analyzer/latest/APIReference/API_AnalyzerSummary.html
8+
9+
-The primary key for this table is **arn**.
10+
-
11+
+The primary key for this table is **_cq_id**.
12+
+The following field is used to calculate the value of `_cq_id`: **arn**.
13+
## Relations
14+
15+
The following tables depend on aws_accessanalyzer_analyzers:
16+
@@ -16,11 +16,11 @@ The following tables depend on aws_accessanalyzer_analyzers:
17+
18+
| Name | Type |
19+
| ------------- | ------------- |
20+
-|_cq_id|`uuid`|
21+
+|_cq_id (PK)|`uuid`|
22+
|_cq_parent_id|`uuid`|
23+
|account_id|`utf8`|
24+
|region|`utf8`|
25+
-|arn (PK)|`utf8`|
26+
+|arn|`utf8`|
27+
|created_at|`timestamp[us, tz=UTC]`|
28+
|name|`utf8`|
29+
|status|`utf8`|

0 commit comments

Comments
 (0)