Files
openfoodnetwork/db/migrate/20180426145636_create_shipping_method_zone.spree.rb
2018-04-27 17:02:28 +02:00

24 lines
1020 B
Ruby

# This migration comes from spree (originally 20130228210442)
class CreateShippingMethodZone < ActiveRecord::Migration
def up
create_table :shipping_methods_zones, :id => false do |t|
t.integer :shipping_method_id
t.integer :zone_id
end
# This association has been corrected in a latter migration
# but when this database migration runs, the table is still incorrectly named
# 'shipping_methods_zones' instead of 'spre_shipping_methods_zones'
Spree::ShippingMethod.has_and_belongs_to_many :zones, :join_table => 'shipping_methods_zones',
:class_name => 'Spree::Zone',
:foreign_key => 'shipping_method_id'
Spree::ShippingMethod.all.each{|sm| sm.zones << Spree::Zone.find(sm.zone_id)}
remove_column :spree_shipping_methods, :zone_id
end
def down
drop_table :shipping_methods_zones
add_column :spree_shipping_methods, :zone_id, :integer
end
end