Sha256: 64acecd04d04ce7e517c195af7876456c2713dfb864255431235e7440c6f0f3e

Contents?: true

Size: 1.2 KB

Versions: 22

Compression:

Stored size: 1.2 KB

Contents

class ConnectKatelloRootRepositoryToSccRepository < ActiveRecord::Migration[5.2]
  # add SccRepository class, because original one triggers the token_changed_callback
  # which tried to update Katello root repositories
  class SccRepository < ApplicationRecord
    belongs_to :katello_root_repository, class_name: 'Katello::RootRepository'
  end

  class SccProduct < ApplicationRecord
    belongs_to :product, class_name: 'Katello::Product'
    has_and_belongs_to_many :scc_repositories
  end

  def up
    SccProduct.where.not(product_id: nil).each do |scc_p|
      # extract all katello root repository ids from subscribed products
      katello_root_repositories = scc_p.product.root_repositories.map { |r| [r.label, r.id] }.to_h
      # match scc repository and katello repository names
      # katello repository name can be
      # 1) equal to scc repo name
      # 2) equal to scc product id + scc product name + scc repo name
      scc_p.scc_repositories.each do |scc_r|
        katello_root_repositories.each do |katello_label, katello_id|
          scc_r.update!(katello_root_repository_id: katello_id) if katello_label.end_with?(::Katello::Util::Model.labelize(scc_r.name))
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
foreman_scc_manager-4.0.0 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-3.1.1 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-3.1.0 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-3.0.0 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-2.3.0 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-2.2.3 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-2.2.2 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-2.2.1 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-2.2.0 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-2.1.0 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-2.0.0 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-1.8.20 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-1.8.19 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-1.8.18 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-1.8.17 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-1.8.16 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-1.8.15 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-1.8.13 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-1.8.12 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
foreman_scc_manager-1.8.10 db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb