From 519564630bda213bc7ab9034657f95b5938493ed Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Wed, 7 Feb 2024 14:18:53 -0500 Subject: [PATCH] Refs #37148 - Add migration --- ...3_remove_entitlement_mode_host_statuses.rb | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 db/migrate/20240207191223_remove_entitlement_mode_host_statuses.rb diff --git a/db/migrate/20240207191223_remove_entitlement_mode_host_statuses.rb b/db/migrate/20240207191223_remove_entitlement_mode_host_statuses.rb new file mode 100644 index 00000000000..349e09fc405 --- /dev/null +++ b/db/migrate/20240207191223_remove_entitlement_mode_host_statuses.rb @@ -0,0 +1,25 @@ +class RemoveEntitlementModeHostStatuses < ActiveRecord::Migration[6.1] + def up + obsolete_statuses = [ + "Katello::SubscriptionStatus", + "Katello::PurposeStatus", + "Katello::PurposeAddonsStatus", + "Katello::PurposeRoleStatus", + "Katello::PurposeSlaStatus", + "Katello::PurposeUsageStatus" + ] + + ::HostStatus::Status.where(type: obsolete_statuses).delete_all + + ::TablePreference.where(name: "hosts").each do |table_preference| + next unless table_preference.columns.include?("subscription_status") + new_columns = table_preference.columns - ["subscription_status"] + if new_columns.present? + table_preference.columns = new_columns + table_preference.save(validate: false) + else + table_preference.destroy + end + end + end +end