Skip to content

Implement common Delete/Update/Create function in DbObject#1126

Merged
MR2011 merged 10 commits intomainfrom
mikrzyz/issue-1089.2
Mar 19, 2026
Merged

Implement common Delete/Update/Create function in DbObject#1126
MR2011 merged 10 commits intomainfrom
mikrzyz/issue-1089.2

Conversation

@michalkrzyz
Copy link
Collaborator

@michalkrzyz michalkrzyz commented Mar 11, 2026

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)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

  • Related Issue # (issue)
  • Closes # (issue)
  • Fixes # (issue)

Remove if not applicable

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

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?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-1089.2 branch 3 times, most recently from 6bcacf9 to 0152c1d Compare March 17, 2026 17:24
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>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-1089.2 branch from 0152c1d to 55b1e5f Compare March 17, 2026 18:14
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-1089.2 branch from 55b1e5f to 19e46a0 Compare March 17, 2026 18:59
@michalkrzyz michalkrzyz changed the title Implement common Delete function in DbObject Implement common Delete/Update/Create function in DbObject Mar 17, 2026
@michalkrzyz michalkrzyz marked this pull request as ready for review March 17, 2026 19:11
Copilot AI review requested due to automatic review settings March 17, 2026 19:11
Copy link
Contributor

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.

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 common Create/Update/Delete methods using github.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.

michalkrzyz and others added 2 commits March 18, 2026 11:07
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
@MR2011 MR2011 merged commit e93c2b3 into main Mar 19, 2026
9 checks passed
@MR2011 MR2011 deleted the mikrzyz/issue-1089.2 branch March 19, 2026 09:45
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