Sha256: cfe64cfad56a16726d20fbcf83a01253990f0d4ca7a469a2258abe2f103df5fa

Contents?: true

Size: 1.31 KB

Versions: 160

Compression:

Stored size: 1.31 KB

Contents

class AddPurposeAddons < ActiveRecord::Migration[5.2]
  def change
    create_table :katello_purpose_addons do |t|
      t.string :name, null: false
    end

    create_table :katello_subscription_facet_purpose_addons do |t|
      t.references :purpose_addon, index: { name: :katello_sub_facet_purpose_addons_paid }
      t.references :subscription_facet, index: { name: :katello_sub_facet_purpose_addons_sfid }
    end

    add_foreign_key :katello_subscription_facet_purpose_addons, :katello_subscription_facets, column: :subscription_facet_id, name: :katello_sub_facet_purpose_addon_facet_id
    add_foreign_key :katello_subscription_facet_purpose_addons, :katello_purpose_addons, column: :purpose_addon_id, name: :katello_sub_facet_purpose_addon_purpose_addon_id

    Katello::Host::SubscriptionFacet.pluck(:id, :purpose_addons).each do |facet|
      yaml_string = facet[1]
      next if yaml_string.nil?

      parsed = YAML.parse(yaml_string)
      addon_names = parsed.root.children.map(&:value)
      addon_names.each do |addon|
        purpose_addon = Katello::PurposeAddon.find_or_create_by(name: addon)
        Katello::SubscriptionFacetPurposeAddon.create(purpose_addon_id: purpose_addon.id, subscription_facet_id: facet[0])
      end
    end

    remove_column :katello_subscription_facets, :purpose_addons, :text
  end
end

Version data entries

160 entries across 160 versions & 1 rubygems

Version Path
katello-4.7.3 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.7.2 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.7.1 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.6.2.1 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.6.2 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.7.0 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.6.1 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.7.0.rc2 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.7.0.rc1 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.4.2.2 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.4.2.1 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.4.2 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.5.1 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.6.0 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.6.0.rc2 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.6.0.rc1 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.5.0 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.5.0.rc2 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.4.1 db/migrate/20190605014649_add_purpose_addons.rb
katello-4.5.0.rc1 db/migrate/20190605014649_add_purpose_addons.rb