Skip to content

Commit

Permalink
Refs #37148 - update migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Feb 6, 2024
1 parent ba7ef68 commit 81be63a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions db/migrate/20200818192230_update_system_purpose_status.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
class UpdateSystemPurposeStatus < ActiveRecord::Migration[6.0]
def change
purpose_types = Katello::HostStatusManager::PURPOSE_STATUS.map(&:to_s)
purpose_types = [
"Katello::PurposeStatus",
"Katello::PurposeAddonsStatus",
"Katello::PurposeRoleStatus",
"Katello::PurposeSlaStatus",
"Katello::PurposeUsageStatus"
]

# load both sets of host statuses and *then* update them to make sure we update the correct statuses
unknown_statuses = ::HostStatus::Status.where(type: purpose_types, status: 2).pluck(:id)
matched_statuses = ::HostStatus::Status.where(type: purpose_types, status: 0).pluck(:id)

::HostStatus::Status.where(id: unknown_statuses).update_all(status: Katello::PurposeStatus::UNKNOWN) # 2 => 0
::HostStatus::Status.where(id: matched_statuses).update_all(status: Katello::PurposeStatus::MATCHED) # 0 => 2
::HostStatus::Status.where(id: unknown_statuses).update_all(status: 0) # 2 => 0
::HostStatus::Status.where(id: matched_statuses).update_all(status: 2) # 0 => 2
end
end

0 comments on commit 81be63a

Please sign in to comment.