-
Notifications
You must be signed in to change notification settings - Fork 29
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
CNF-15570: Add support for updating only some fields #376
Conversation
This makes changes to the Update utility so that it is possible to request that only some fields be set in the update operation. This is to facilitate changes required by the upcoming resource data collector functionality that will be synchronizing data between ACM and our persistent storage. Signed-off-by: Allain Legacy <[email protected]>
@alegacy: This pull request references CNF-15570 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.19.0" version, but no target version was set. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
||
// Return all columns to get any defaulted values that the DB may set | ||
query := psql.Insert(im.Into(record.TableName()), im.Returning("*")) | ||
query := psql.Insert(im.Into(record.TableName()), im.Returning(tags.Columns()...)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting this back in because it makes the code too fragile. If we add columns to the table, but forget to add them to the model it causes an error. Until we have a better unit test strategy we should avoid making this more fragile than necessary.
// will contain all columns. | ||
func Update[T db.Model](ctx context.Context, db *pgxpool.Pool, record T, uuid uuid.UUID, fields ...string) (*T, error) { | ||
all := GetAllDBTagsFromStruct(record) | ||
tags := GetDBTagsFromStructFields(record, fields...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is how I imaged some specific columns to be selected in Find, FindAll and Search, instead of passing []any for columns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I'll rework those other ones in a future PR.
@@ -21,6 +21,16 @@ func (r DBTag) Columns() []any { | |||
return columns | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see all this being used anywhere. Let's keep this pr clean and introduce CompareObjects
later when is used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this intentionally to reduce the size of the upcoming PRs. I wanted to avoid one huge PR with everything in it since it makes it difficult to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that and I'm not trying to be picky. It is just a good practice. These parts are not too big. Let's introduce them later.
As requested, combined into #379 |
This makes changes to the Update utility so that it is possible to request that only some fields be set in the update operation. This is to facilitate changes required by the upcoming resource data collector functionality that will be synchronizing data between ACM and our persistent storage.