diff --git a/Rakefile b/Rakefile index 862a92d..9acaeca 100644 --- a/Rakefile +++ b/Rakefile @@ -21,3 +21,25 @@ task regenerate_images: :environment do end end end + +task update_cities: :environment do + Location.all.each do |l| + city = City.search(([l.city, l.territory, l.country] - [nil, '']).join(', ')) + l.city_id = city.id + l.save! + end + + City.all.each do |c| + location = Geocoder.search(c.address, language: 'en').first + c.place_id = location.data['place_id'] + c.save! + end +end + +task update_cities_es: :environment do + City.all.each do |c| + city = c.get_translation(:es) + c.set_column_for_locale(:city, :es, city, 0) unless city.blank? || city == c.get_column_for_locale(:city, :es) + c.save! + end +end diff --git a/db/migrate/20161201011655_add_place_id_to_city.rb b/db/migrate/20161201011655_add_place_id_to_city.rb index 2765e3a..d371c6e 100644 --- a/db/migrate/20161201011655_add_place_id_to_city.rb +++ b/db/migrate/20161201011655_add_place_id_to_city.rb @@ -3,11 +3,5 @@ require 'geocoder/calculations' class AddPlaceIdToCity < ActiveRecord::Migration def change add_column :cities, :place_id, :string - - City.all.each do |c| - location = Geocoder.search(c.address, language: 'en').first - c.place_id = location.data['place_id'] - c.save! - end end end diff --git a/db/migrate/20161201015559_add_city_id_to_location.rb b/db/migrate/20161201015559_add_city_id_to_location.rb index 75830cd..b91becf 100644 --- a/db/migrate/20161201015559_add_city_id_to_location.rb +++ b/db/migrate/20161201015559_add_city_id_to_location.rb @@ -1,11 +1,5 @@ class AddCityIdToLocation < ActiveRecord::Migration def change add_column :locations, :city_id, :integer - - Location.all.each do |l| - city = City.search(([l.city, l.territory, l.country] - [nil, '']).join(', ')) - l.city_id = city.id - l.save! - end end end diff --git a/db/migrate/20161201021349_add_spanish_city_translations.rb b/db/migrate/20161201021349_add_spanish_city_translations.rb index 2aa475d..6ea9c86 100644 --- a/db/migrate/20161201021349_add_spanish_city_translations.rb +++ b/db/migrate/20161201021349_add_spanish_city_translations.rb @@ -1,9 +1,4 @@ class AddSpanishCityTranslations < ActiveRecord::Migration def change - City.all.each do |c| - city = c.get_translation(:es) - c.set_column_for_locale(:city, :es, city, 0) unless city.blank? || city == c.get_column_for_locale(:city, :es) - c.save! - end end end