Last active
August 27, 2015 11:29
-
-
Save inkmix/3153c21d34f6087b5e8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
country = 'nl' | |
wdays = [3,5,6] | |
nl_zipcodes = CSV.read('zipcodes_nl.csv').map(&:first) | |
existing_zipcodes = DeliveryZip.for_country(country).pluck(:zip) | |
added_zips = nl_zipcodes - existing_zipcodes | |
existing_zips_not_in_file = existing_zipcodes - nl_zipcodes | |
ActiveRecord::Base.transaction do | |
wdays.each do |wday| | |
slot_ids = DeliverySlot.for_country(country).joins(:delivery_slot_week_days). | |
where(delivery_slot_week_days: {wday: wday}).pluck(:id).uniq | |
nl_zipcodes.each do |zipcode| | |
delivery_zip = DeliveryZip.find_or_create_by(zip: zipcode, country: country) | |
slot_ids.each do |slot_id| | |
DeliveryZipDeliverySlot.find_or_create_by(delivery_zip_id: delivery_zip.id, delivery_slot_id: slot_id) | |
DeliverySlotWeekDay.find_or_create_by(delivery_zip_id: delivery_zip.id, delivery_slot_id: slot_id, wday: wday) | |
end | |
end | |
end | |
end | |
puts "zipcodes that were not in the system yet: #{added_zips}" | |
puts "zipcodes that are in the system but not in the file #{existing_zips_not_in_file}" |
slots = DeliverySlot.for_country(country).joins(:delivery_slot_week_days).where(:'delivery_slot_week_days.wday' => wdays).uniq
could be
slots = DeliverySlot.for_country(country).joins(:delivery_slot_week_days).where(delivery_slot_week_days: {wday: wdays}).uniq
But it's just cosmetic :)
LGTM
ahh! I always forget about this one!! nice
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LGTM