Fixed city migration
This commit is contained in:
parent
1dc608bf58
commit
c85d6c7d75
22
Rakefile
22
Rakefile
@ -21,3 +21,25 @@ task regenerate_images: :environment do
|
|||||||
end
|
end
|
||||||
end
|
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
|
||||||
|
@ -3,11 +3,5 @@ require 'geocoder/calculations'
|
|||||||
class AddPlaceIdToCity < ActiveRecord::Migration
|
class AddPlaceIdToCity < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
add_column :cities, :place_id, :string
|
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
|
||||||
end
|
end
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
class AddCityIdToLocation < ActiveRecord::Migration
|
class AddCityIdToLocation < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
add_column :locations, :city_id, :integer
|
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
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
class AddSpanishCityTranslations < ActiveRecord::Migration
|
class AddSpanishCityTranslations < ActiveRecord::Migration
|
||||||
def change
|
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
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user