ref: master
plugins/sniffer/db/migrate/20131212124106_drop_sniffer_profile_table.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 |
SnifferPlugin.send :remove_const, :Opportunity if defined? SnifferPlugin::Opportunity class SnifferPlugin::Profile < ApplicationRecord belongs_to :profile end class SnifferPlugin::Opportunity < ApplicationRecord belongs_to :sniffer_profile, class_name: 'SnifferPlugin::Profile', foreign_key: :profile_id end class DropSnifferProfileTable < ActiveRecord::Migration def self.up SnifferPlugin::Opportunity.find_each do |opportunity| sniffer_profile = opportunity.sniffer_profile next unless sniffer_profile.profile opportunity.profile_id = sniffer_profile.profile.id opportunity.save! end drop_table :sniffer_plugin_profiles end def self.down end end |