Sha256: 6205d15c0328894293bd5051e122fee8847f348e8463eb2a5ce643e5957a540e

Contents?: true

Size: 746 Bytes

Versions: 140

Compression:

Stored size: 746 Bytes

Contents

class FixTaxableTaxonomiesJobTemplate < ActiveRecord::Migration[4.2]
  def up
    # we need to count on the fact that the user might already has assigned the templates
    # to taxonomies after the previous update
    already_present = TaxableTaxonomy.where(:taxable_type => 'JobTemplate').pluck(:taxable_id)
    missing = JobTemplate.unscoped.pluck(:id) - already_present
    TaxableTaxonomy.unscoped.where(:taxable_type => 'Template', :taxable_id => missing).update_all(:taxable_type => 'JobTemplate')
    TaxableTaxonomy.unscoped.where(:taxable_type => 'Template', :taxable_id => already_present).delete_all
  end

  def down
    TaxableTaxonomy.unscoped.where(:taxable_type => 'JobTemplate').update_all(:taxable_type => 'Template')
  end
end

Version data entries

140 entries across 140 versions & 1 rubygems

Version Path
foreman_remote_execution-4.2.3 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-4.2.2 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-4.2.1 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-4.2.0 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-4.1.0 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.3.7 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-4.0.0 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.3.6 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.3.5 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.3.4 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.3.3 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.2.2 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.3.2 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.3.1 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.3.0 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.2.1 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.2.0 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-3.1.0 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-2.0.10 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
foreman_remote_execution-2.0.9 db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb