Sha256: 2aa0bf67d05c42db957ca57d8f0fe7eae39c9bc6bbdd7cfa0bcb48a14e7d07d7

Contents?: true

Size: 494 Bytes

Versions: 8

Compression:

Stored size: 494 Bytes

Contents

class AddSectionTypeIdToSections < ActiveRecord::Migration[5.1]
  def change
  	add_reference :sections, :section_type, index: true

  	begin
	  	Dhatu::Section.all.each do |section|
	  		section_type = Dhatu::SectionType.find_by_code(section.section_type) || Dhatu::SectionType.create(title: section.section_type.titleize, code: section.section_type)
	  		section.update_attribute(section_type_id: section_type.id)
	  	end
	  rescue
	  end

  	remove_column :sections, :section_type
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dhatu-0.1.25 db/migrate/20171120145547_add_section_type_id_to_sections.rb
dhatu-0.1.24 db/migrate/20171120145547_add_section_type_id_to_sections.rb
dhatu-0.1.23 db/migrate/20171120145547_add_section_type_id_to_sections.rb
dhatu-0.1.22 db/migrate/20171120145547_add_section_type_id_to_sections.rb
dhatu-0.1.21 db/migrate/20171120145547_add_section_type_id_to_sections.rb
dhatu-0.1.20 db/migrate/20171120145547_add_section_type_id_to_sections.rb
dhatu-0.1.19 db/migrate/20171120145547_add_section_type_id_to_sections.rb
dhatu-0.1.18 db/migrate/20171120145547_add_section_type_id_to_sections.rb