Sha256: ecd4d7fe6467fa78d2b695e375432581e1edf535e5f4bd5d4ca06e8a02c21579

Contents?: true

Size: 1.15 KB

Versions: 23

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

class ChangeTemplatekindToBootdisk < ActiveRecord::Migration[4.2]
  class FakeConfigTemplate < ApplicationRecord
    self.table_name = if ActiveRecord::Base.connection.data_source_exists?("config_templates")
                        'config_templates'
                      else
                        'templates'
                      end
    self.inheritance_column = :_type_disabled
  end

  def self.up
    kind = TemplateKind.where(name: 'Bootdisk').first_or_create

    tmpl_h = Setting.find_by(name: 'bootdisk_host_template').try(:value)
    tmpl_g = Setting.find_by(name: 'bootdisk_generic_host_template').try(:value)

    FakeConfigTemplate.unscoped.where('name LIKE ?', '%Boot disk%').update_all(template_kind_id: kind.id)
    FakeConfigTemplate.unscoped.where(name: [tmpl_h, tmpl_g].compact).update_all(template_kind_id: kind.id)
  end

  def self.down
    old_kind = TemplateKind.find_by(name: 'Bootdisk')
    new_kind = TemplateKind.find_by(name: 'iPXE')
    return unless old_kind.present? && new_kind.present?

    FakeConfigTemplate.unscoped.where(template_kind_id: old_kind.id).update_all(template_kind_id: new_kind.id)
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
foreman_bootdisk-22.0.2 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-22.0.1 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-22.0.0 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.0.6 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.2.3 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.2.2 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.0.5 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.2.1 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.2.0 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.1.0 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-19.0.9 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.0.4 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.0.3 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-19.0.8 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.0.2 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-19.0.7 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.0.1 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-21.0.0 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-19.0.6 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb
foreman_bootdisk-19.0.4.1 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb