Sha256: 4b6b23daaaea2c123da90ed3166f7761357bd018a109004e9596dae6640f12e3

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

class ChangeTemplatekindToBootdisk < ActiveRecord::Migration[4.2]
  class FakeConfigTemplate < ApplicationRecord
    self.table_name = if defined? ConfigTemplate
                        'config_templates'
                      else
                        'templates'
                      end
  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%') |
      FakeConfigTemplate.unscoped.where(name: [tmpl_h, tmpl_g].compact)).each do |tmpl|
      tmpl.update_attribute(:template_kind_id, kind.id)
    end
  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

1 entries across 1 versions & 1 rubygems

Version Path
foreman_bootdisk-19.0.1 db/migrate/20140522185700_change_templatekind_to_bootdisk.rb