ref: master
db/migrate/033_destroy_organization_and_person_infos.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration def self.up Person.find_each do |i| info = ApplicationRecord.connection.select_one("select * from person_infos where person_id = #{i.id}") i.name = info["name"] unless info["name"].nil? i.address = info["address"] unless info["address"].nil? [ "photo", "contact_information", "birth_date", "sex", "city", "state", "country" ].each do |field| i.send("#{field}=", info[field]) end i.save! end drop_table :person_infos Organization.find_each do |i| info = ApplicationRecord.connection.select_one("select * from organization_infos where organization_id = #{i.id}") [ "contact_person", "contact_email", "acronym", "foundation_year", "legal_form", "economic_activity", "management_information", "validated" ].each do |field| i.send("#{field}=", info[field]) end i.save! end drop_table :organization_infos end def self.down raise "this migration can't be reverted" end end |