-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #36310 - Migrate off ContentViews generated for repository export
Author: William Bradford Clark <[email protected]> Co-authored-by: Partha Aji <[email protected]> Ensures no Hosts remain on ContentViews generated for repository export. If doing so would leave the Host a valid ContentView, the Default Organization View is assigned to it. Also implements additional filtering in the candlepin proxies controller, and several additional tests.
- Loading branch information
Showing
5 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
47 changes: 47 additions & 0 deletions
47
db/migrate/20240815080259_migrate_off_generated_content_views.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class MigrateOffGeneratedContentViews < ActiveRecord::Migration[6.1] | ||
class FakeCVECF < ApplicationRecord | ||
self.table_name = 'katello_content_view_environment_content_facets' | ||
end | ||
|
||
def up | ||
say_with_time "Migrating hosts off generated content views" do | ||
migrate_hosts | ||
end | ||
end | ||
|
||
def down | ||
say "This migration cannot be reversed", true | ||
end | ||
|
||
private | ||
|
||
def migrate_hosts | ||
say_with_time "Migrating hosts..." do | ||
generated_content_views = Katello::ContentView.generated_for_repository | ||
|
||
facets = Katello::Host::ContentFacet.joins(:content_view_environments). | ||
where(content_view_environments: { content_view: generated_content_views }) | ||
facets.all.each do |content_facet| | ||
valid_cves = content_facet.content_view_environments.where.not(content_view: generated_content_views) | ||
if valid_cves.empty? | ||
organization = content_facet.host.organization | ||
default_cve = organization.content_view_environments.find_by(lifecycle_environment: organization.library, | ||
content_view: organization.default_content_view) | ||
if default_cve | ||
FakeCVECF.where(content_facet_id: content_facet).delete_all | ||
FakeCVECF.create!(content_facet_id: content_facet.id, | ||
content_view_environment_id: default_cve.id) | ||
say "Replaced all content views with Default Organization View for host #{content_facet.host.name}", true | ||
else | ||
say "No Default Organization View found for host #{content_facet.host.name}. Skipping.", true | ||
end | ||
else | ||
FakeCVECF.where(content_facet_id: content_facet). | ||
where.not(content_view_environment_id: valid_cves). | ||
delete_all | ||
say "Removed offending content views for host #{content_facet.host.name}", true | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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