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

CNF-15570: Add support for updating only some fields #376

Closed

Conversation

alegacy
Copy link
Collaborator

@alegacy alegacy commented Dec 5, 2024

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.

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]>
@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Dec 5, 2024

@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:

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.

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.

Copy link

openshift-ci bot commented Dec 5, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from alegacy. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment


// 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()...))
Copy link
Collaborator Author

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...)
Copy link
Contributor

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

Copy link
Collaborator Author

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
}

Copy link
Contributor

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

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

@alegacy
Copy link
Collaborator Author

alegacy commented Dec 5, 2024

As requested, combined into #379

@alegacy alegacy closed this Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants