diff --git a/db/migrate/20161205095624_replacing_organisation_types_with_bitflags.rb b/db/migrate/20161205095624_replacing_organisation_types_with_bitflags.rb new file mode 100644 index 0000000..16be879 --- /dev/null +++ b/db/migrate/20161205095624_replacing_organisation_types_with_bitflags.rb @@ -0,0 +1,40 @@ +class ReplacingOrganisationTypesWithBitflags < ActiveRecord::Migration + # requires flag_shih_tzu for bitfields + def change + # add org_type field to orgs + change_table :orgs do |t| + t.integer :org_type, null: false, default: 0 # flag_shih_tzu-managed bitfield + # Effective booleans which will be stored on the flags column: + # t.boolean :Organisation + # t.boolean :Funder + # t.boolean :Institution + # t.boolean :Reaserch_Institution + # t.boolean :School + # t.boolean :Project + end + # migrate old org_type data to bitfield + Org.includes(:organisation_type).all.each do |org| + unless org.organisation_type.nil? + case org.organisation_type.name + when "Organisation" + org.organisation = true + when "Funder" + org.funder = true + when "Project" + org.project = true + when "School" + org.school = true + when "Institution" + org.institution = true + when "Research Institute" + org.research_institute = true + end + org.save! + end + end + # remove organisation_type_id field from orgs + remove_column :orgs, :organisation_type_id + # remove organisation_type table + drop_table :organisation_types + end +end diff --git a/db/migrate/20161212152020_replacing_organisation_types_with_bitflags.rb b/db/migrate/20161212152020_replacing_organisation_types_with_bitflags.rb deleted file mode 100644 index 16be879..0000000 --- a/db/migrate/20161212152020_replacing_organisation_types_with_bitflags.rb +++ /dev/null @@ -1,40 +0,0 @@ -class ReplacingOrganisationTypesWithBitflags < ActiveRecord::Migration - # requires flag_shih_tzu for bitfields - def change - # add org_type field to orgs - change_table :orgs do |t| - t.integer :org_type, null: false, default: 0 # flag_shih_tzu-managed bitfield - # Effective booleans which will be stored on the flags column: - # t.boolean :Organisation - # t.boolean :Funder - # t.boolean :Institution - # t.boolean :Reaserch_Institution - # t.boolean :School - # t.boolean :Project - end - # migrate old org_type data to bitfield - Org.includes(:organisation_type).all.each do |org| - unless org.organisation_type.nil? - case org.organisation_type.name - when "Organisation" - org.organisation = true - when "Funder" - org.funder = true - when "Project" - org.project = true - when "School" - org.school = true - when "Institution" - org.institution = true - when "Research Institute" - org.research_institute = true - end - org.save! - end - end - # remove organisation_type_id field from orgs - remove_column :orgs, :organisation_type_id - # remove organisation_type table - drop_table :organisation_types - end -end