Skip to content
Snippets Groups Projects
Commit e4f8ee7c authored by Alex Reisner's avatar Alex Reisner
Browse files

Add migration generator for geolite city database.

parent 5855303e
No related branches found
No related tags found
No related merge requests found
require 'rails/generators/migration'
module Geocoder
module Generators
class MaxmindGenerator < Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
def copy_migration_files
migration_template "migration/maxmind_geolite_city.rb", "db/migrate/geocoder_maxmind_geolite_city.rb"
end
# Define the next_migration_number method (necessary for the
# migration_template method to work)
def self.next_migration_number(dirname)
if ActiveRecord::Base.timestamped_migrations
sleep 1 # make sure each time we get a different timestamp
Time.new.utc.strftime("%Y%m%d%H%M%S")
else
"%.3d" % (current_migration_number(dirname) + 1)
end
end
end
end
end
\ No newline at end of file
class GeocoderMaxmindGeoliteCity < ActiveRecord::Migration
def change
create_table :maxmind_blocks, id: false do |t|
t.column :startIpNum, 'integer unsigned', null: false
t.column :endIpNum, 'integer unsigned', null: false
t.column :locId, 'integer unsigned', null: false
end
add_index :maxmind_blocks, :startIpNum, unique: true
create_table :maxmind_location, id: false do |t|
t.column :locId, 'integer unsigned', null: false
t.string :country, null: false
t.string :region, null: false
t.string :city
t.string :postalCode, null: false
t.float :latitude
t.float :longitude
t.integer :dmaCode
t.integer :areaCode
end
add_index :maxmind_location, :locId, unique: true
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment