X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/95e8c63c2a3aee63c3eb21d7b70343ff1d17f652..4eb2e318afd080f89e76c664a75ba7e09b31fd91:/db/migrate/031_create_countries.rb?ds=sidebyside diff --git a/db/migrate/031_create_countries.rb b/db/migrate/031_create_countries.rb index 337e86fde..c26bdd08c 100644 --- a/db/migrate/031_create_countries.rb +++ b/db/migrate/031_create_countries.rb @@ -1,36 +1,17 @@ -require 'migrate' -require 'rexml/document' +require "rexml/document" -class CreateCountries < ActiveRecord::Migration +class CreateCountries < ActiveRecord::Migration[4.2] def self.up - create_table :countries, innodb_table do |t| - t.column :id, :integer_pk, :null => false - t.column :code, :string, :limit => 2, :null => false - t.column :min_lat, :double, :null => false - t.column :max_lat, :double, :null => false - t.column :min_lon, :double, :null => false - t.column :max_lon, :double, :null => false + create_table :countries, :id => false do |t| + t.column :id, :primary_key, :null => false + t.column :code, :string, :limit => 2, :null => false + t.column :min_lat, :float, :limit => 53, :null => false + t.column :max_lat, :float, :limit => 53, :null => false + t.column :min_lon, :float, :limit => 53, :null => false + t.column :max_lon, :float, :limit => 53, :null => false end add_index :countries, [:code], :name => "countries_code_idx", :unique => true - - Net::HTTP.start('ws.geonames.org') do |http| - xml = REXML::Document.new(http.get("/countryInfo").body) - - xml.elements.each("geonames/country") do |ele| - code = ele.get_text("countryCode").to_s - minlon = ele.get_text("bBoxWest").to_s - minlat = ele.get_text("bBoxSouth").to_s - maxlon = ele.get_text("bBoxEast").to_s - maxlat = ele.get_text("bBoxNorth").to_s - - Country.create( - :code => code, - :min_lat => minlat.to_f, :max_lat => maxlat.to_f, - :min_lon => minlon.to_f, :max_lon => maxlon.to_f - ) - end - end end def self.down