Sha256: d3a0d2e85649e06e2f3585a6e5968b13e189ed17f1924b7b7a1afb8ab8d7af93

Contents?: true

Size: 701 Bytes

Versions: 7

Compression:

Stored size: 701 Bytes

Contents

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foreman_remote_execution-14.0.1 db/migrate/20240522093413_migrate_smart_proxy_ids_to_template_invocations.rb
foreman_remote_execution-13.2.6 db/migrate/20240522093413_migrate_smart_proxy_ids_to_template_invocations.rb
foreman_remote_execution-14.0.0 db/migrate/20240522093413_migrate_smart_proxy_ids_to_template_invocations.rb
foreman_remote_execution-13.2.5 db/migrate/20240522093413_migrate_smart_proxy_ids_to_template_invocations.rb
foreman_remote_execution-13.2.4 db/migrate/20240522093413_migrate_smart_proxy_ids_to_template_invocations.rb
foreman_remote_execution-13.2.3 db/migrate/20240522093413_migrate_smart_proxy_ids_to_template_invocations.rb
foreman_remote_execution-13.2.2 db/migrate/20240522093413_migrate_smart_proxy_ids_to_template_invocations.rb