Implement common Delete/Update/Create function in DbObject#1126
Merged
Implement common Delete/Update/Create function in DbObject#1126
Conversation
6bcacf9 to
0152c1d
Compare
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com> Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com> Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com> Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com> Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com> Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com> Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
0152c1d to
55b1e5f
Compare
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com> Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
55b1e5f to
19e46a0
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the MariaDB data-access layer to reduce duplicated CRUD SQL by introducing a generic DbObject with common Create/Update/Delete operations built via the Squirrel SQL builder. To support this, multiple entities gain a small GetId/SetId interface, and tests are updated to match the new behavior and constructors.
Changes:
- Introduce a generic
DbObject[T]with commonCreate/Update/Deletemethods usinggithub.com/Masterminds/squirrel. - Add
entity.Entity(GetId/SetId) and implement it across multiple entity types. - Update MariaDB repositories and tests to use the new generic CRUD and updated constructors; update module dependencies accordingly.
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| scanner/k8s-assets/go.mod | Bumps Go version for the k8s-assets scanner module. |
| go.mod | Adds Squirrel dependency and bumps Go version; adjusts direct/indirect requirements. |
| go.sum | Updates sums for new/updated dependencies (e.g., Squirrel). |
| internal/entity/common.go | Adds Json.Value() and introduces entity.Entity interface for generic CRUD. |
| internal/entity/user.go | Implements GetId/SetId for User. |
| internal/entity/support_group.go | Implements GetId/SetId for SupportGroup. |
| internal/entity/service.go | Implements GetId/SetId for Service. |
| internal/entity/remediation.go | Implements GetId/SetId for Remediation. |
| internal/entity/patch.go | Implements GetId/SetId for Patch. |
| internal/entity/issue_variant.go | Implements GetId/SetId for IssueVariant. |
| internal/entity/issue_repository.go | Implements GetId/SetId via BaseIssueRepository. |
| internal/entity/issue_match.go | Implements GetId/SetId for IssueMatch. |
| internal/entity/issue.go | Implements GetId/SetId for Issue. |
| internal/entity/component_version.go | Implements GetId/SetId for ComponentVersion. |
| internal/entity/component_instance.go | Implements GetId/SetId for ComponentInstance. |
| internal/entity/component.go | Implements GetId/SetId for Component. |
| internal/e2e/issue_variant_query_test.go | Updates seeding/construction to new AsIssueVariant() signature. |
| internal/database/mariadb/db_object.go | Replaces ad-hoc SQL string building with generic CRUD using Squirrel; introduces WrapAccess/arg-based exec helpers. |
| internal/database/mariadb/entity.go | Adds Row[T] adapters and updates IssueVariantRow.AsIssueVariant() signature; introduces empty FromEntity for ServiceIssueVariantRow. |
| internal/database/mariadb/component.go | Migrates Component CRUD to generic DbObject.Create/Update/Delete. |
| internal/database/mariadb/component_instance.go | Migrates ComponentInstance CRUD to generic DbObject.Create/Update/Delete. |
| internal/database/mariadb/component_version.go | Migrates ComponentVersion CRUD to generic DbObject.Create/Update/Delete. |
| internal/database/mariadb/issue.go | Migrates Issue CRUD to generic DbObject.Create/Update/Delete. |
| internal/database/mariadb/issue_match.go | Migrates IssueMatch CRUD to generic DbObject.Create/Update/Delete. |
| internal/database/mariadb/issue_repository.go | Migrates IssueRepository CRUD to generic DbObject.Create/Update/Delete. |
| internal/database/mariadb/issue_variant.go | Migrates IssueVariant CRUD to generic DbObject.Create/Update/Delete and updates row conversion usage. |
| internal/database/mariadb/remediation.go | Migrates Remediation CRUD to generic DbObject.Create/Update/Delete. |
| internal/database/mariadb/service.go | Migrates Service CRUD to generic DbObject.Create/Update/Delete. |
| internal/database/mariadb/support_group.go | Migrates SupportGroup CRUD to generic DbObject.Create/Update/Delete. |
| internal/database/mariadb/user.go | Migrates User CRUD to generic DbObject.Create/Update/Delete. |
| internal/database/mariadb/patch.go | Updates patchObject to new generic type (used for filtering). |
| internal/database/mariadb/service_issue_variant.go | Updates serviceIssueVariantObject to new generic type (used for filtering). |
| internal/database/mariadb/issue_variant_test.go | Updates tests to new AsIssueVariant() signature. |
| internal/database/mariadb/uniqueness_test.go | Updates duplication assertion to match new (raw) DB error output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com> Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
MR2011
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On-behalf-of: SAP Michal Krzyz michal.krzyz@sap.com
Description
Reduce database redundant code
Apply sql query builder (squirrel)
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.
What type of PR is this? (check all applicable)
Related Tickets & Documents
Added tests?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Added to documentation?
Checklist