Skip to content

Commit

Permalink
Fixes #37493 - Migrate historical data
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka authored and ares committed Jul 10, 2024
1 parent c66a641 commit e3578d6
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class MigrateSmartProxyIdsToTemplateInvocations < ActiveRecord::Migration[6.0]
def up
ForemanTasks::Link.joins(:task)
.where(resource_type: 'SmartProxy', task: { label: 'Actions::RemoteExecution::RunHostJob' })
.where.not(resource_id: nil)
.find_in_batches do |batch|
batch.group_by(&:resource_id).each do |resource_id, links|
template_invocation_ids = ForemanTasks::Link.where(resource_type: 'TemplateInvocation', task_id: links.map(&:task_id)).select(:resource_id)
TemplateInvocation.where(id: template_invocation_ids).update_all(smart_proxy_id: resource_id)
end
end
end

def down
end
end

0 comments on commit e3578d6

Please sign in to comment.