Skip to content

Fixes #38504 - delete installed package dupes before evr migration #11421

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ianballou
Copy link
Member

@ianballou ianballou commented Jun 17, 2025

What are the changes introduced in this pull request?

Deletes duplicate katello_installed_package records and katello_host_installed_package records to avoid issues from https://postgresql.verite.pro/blog/2018/08/27/glibc-upgrade.html

This is just to help users complete their upgrade. Their databases still need a full reindex after getting past this.

Considerations taken when implementing this change?

I tried to keep the same logical flow as the solution in https://access.redhat.com/solutions/7053489.

What are the testing steps for this pull request?

  1. Start with a Katello nightly machine that doesn't have this migration (Katello 4.15)
  2. Run DROP INDEX index_katello_installed_packages_on_nvrea;` to remove the index
  3. Create duplicate InstalledPackage records and HostInstalledPackage records linked up to them. Ensure some host has a number of duplicates assigned to it along with a spread across other hosts. This is important to check because the code was written specifically to not error out if a HostInstalledPackage is "fixed" and results in a duplicate being saved that originally pointed to one of the duplicate InstalledPackage records.
  4. Upgrade to Katello 4.16 and see if you can recreate the index:
CREATE UNIQUE INDEX index_katello_installed_packages_on_nvrea ON katello_installed_packages (nvrea);

Alternatively, the code could be tested outside of the migration with the duplicates being the test point.

Summary by Sourcery

Remove duplicate katello_installed_package and katello_host_installed_package records in the up migration to ensure EVR index recreation succeeds during upgrades

Bug Fixes:

  • Delete duplicate installed package and host-installed-package records grouped by nvrea to avoid post-upgrade index conflicts

Enhancements:

  • Add fix_installed_package_dupes method to consolidate host associations to the original installed package record before deletion
  • Invoke the duplicate-removal step in the up migration prior to EVR extension and index recreation

Copy link

sourcery-ai bot commented Jun 17, 2025

Reviewer's Guide

Adds a pre-index deduplication step in the migration by introducing fix_installed_package_dupes to identify duplicate InstalledPackage entries (grouped by nvrea), purge or reassign related HostInstalledPackage records, and delete the duplicates before attempting to recreate the unique index.

File-Level Changes

Change Details Files
Introduced fix_installed_package_dupes method for deduplicating packages
  • Group InstalledPackage records by nvrea and identify those with counts > 1
  • Select the first record as original and collect duplicate IDs
  • Delete HostInstalledPackage links where hosts already reference the original
  • Reassign remaining HostInstalledPackage records to the original package
  • Remove duplicate InstalledPackage records
db/migrate/20240924161240_katello_recreate_evr_constructs.rb
Hooked deduplication into migration up flow
  • Call fix_installed_package_dupes at the start of up method
  • Ensure deduplication runs before unique index recreation
db/migrate/20240924161240_katello_recreate_evr_constructs.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ianballou - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ianballou ianballou force-pushed the 38504-evr-migration-dupe-fix branch from d7f93db to d5c312b Compare June 18, 2025 14:24
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.

1 participant