Skip to content

Commit

Permalink
Fixes #34703 - Destroy duplicate errata child records (Katello#10041)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Mar 31, 2022
1 parent 29bf01b commit eb67c60
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions db/migrate/20220303160220_remove_duplicate_errata.rb
Expand Up @@ -12,7 +12,7 @@ def up
#For duplicate errata,
# a) update all RepositoryErrata to point to unique errata,
# b) if repo-errata association for that combination exists, delete duplicate errata association
# c) Delete all duplicate errata
# c) Delete all duplicate errata and child records
::Katello::Erratum.group(:errata_id).having("count(errata_id) > 1").pluck(:errata_id).each do |original_errata_id|
errata_to_keep = ::Katello::Erratum.find_by(pulp_id: original_errata_id)
errata_all = ::Katello::Erratum.where(errata_id: original_errata_id)
Expand All @@ -24,7 +24,13 @@ def up
repo_erratum.update(erratum_id: errata_to_keep.id)
end
end
::Katello::Erratum.delete(dup_errata&.pluck(:id))
dup_errata_ids = dup_errata&.pluck(:id)
if dup_errata_ids&.present?
::Katello::ErratumPackage.where(:erratum_id => dup_errata_ids).delete_all
::Katello::ErratumBugzilla.where(:erratum_id => dup_errata_ids).delete_all
::Katello::ErratumCve.where(:erratum_id => dup_errata_ids).delete_all
::Katello::Erratum.where(:id => dup_errata_ids).delete_all
end
end
end

Expand Down

0 comments on commit eb67c60

Please sign in to comment.