Browse Source

Fixed city migration

development
Godwin 8 years ago
parent
commit
c85d6c7d75
  1. 22
      Rakefile
  2. 6
      db/migrate/20161201011655_add_place_id_to_city.rb
  3. 6
      db/migrate/20161201015559_add_city_id_to_location.rb
  4. 5
      db/migrate/20161201021349_add_spanish_city_translations.rb

22
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

6
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

6
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

5
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

Loading…
Cancel
Save