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

Fix generated column in unique key error #1461

Merged
merged 10 commits into from
Dec 18, 2024
Merged

Conversation

meiji163
Copy link
Contributor

@meiji163 meiji163 commented Oct 23, 2024

Description

This PR fixes a bug when the unique key contains a virtual column. The update query builder checks uniqueKeyColumns is a subset of sharedColumns which only contains non-virtual columns, so the migration fails.

We can reproduce the bug by adding update DML to the generated-columns-unique test case.

In case this PR introduced Go code changes:

  • contributed code is using same conventions as original code
  • script/cibuild returns with no formatting errors, build errors or unit test errors.

@meiji163 meiji163 marked this pull request as ready for review December 18, 2024 19:38
@Copilot Copilot bot review requested due to automatic review settings December 18, 2024 19:38
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 6 changed files in this pull request and generated 2 comments.

Files not reviewed (2)
  • localtests/generated-columns-unique/create.sql: Language not supported
  • localtests/generated-columns/create.sql: Language not supported
Comments suppressed due to low confidence (1)

go/sql/builder_test.go:691

  • The test case should include a scenario where the unique key columns contain virtual columns to ensure the new logic is covered.
_, err := NewDMLUpdateQueryBuilder(databaseName, tableName, tableColumns, sharedColumns, sharedColumns, uniqueKeyColumns)

Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more

go/sql/builder.go Outdated Show resolved Hide resolved
go/logic/inspect.go Show resolved Hide resolved
@@ -244,6 +245,19 @@ func (this *ColumnList) IsSubsetOf(other *ColumnList) bool {
return true
}

func (this *ColumnList) FilterBy(f func(Column) bool) *ColumnList {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're creating a new instance of ColumnList, what if we turn this method into factory function? Something like:

 NewFilteredColumnList(ordinals ColumnsMap, f func(Column) bool) *ColumnList {
 ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really I just want to filter []Column, but IsSubsetOf is a method of ColumnList so I had to make a new one 😓

go/sql/types.go Outdated Show resolved Hide resolved
go/sql/types.go Outdated Show resolved Hide resolved
susanzhang27
susanzhang27 previously approved these changes Dec 18, 2024
@meiji163 meiji163 merged commit 0fe1190 into master Dec 18, 2024
7 checks passed
@meiji163 meiji163 deleted the meiji163/generated-col-error branch December 18, 2024 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants