Class: CreateMyZipcodeGemModels

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/my_zipcode_gem/templates/migration.rb

Class Method Summary collapse

Class Method Details

.downObject



39
40
41
42
43
# File 'lib/generators/my_zipcode_gem/templates/migration.rb', line 39

def self.down
  drop_table :counties
  drop_table :states
  drop_table :zipcodes
end

.upObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/my_zipcode_gem/templates/migration.rb', line 2

def self.up
  # Zipcodes Table
  create_table :zipcodes do |t|
    t.string :code
    t.string :city
    t.integer :state_id
    t.integer :county_id
    t.string :area_code
    t.decimal :lat, :precision => 15, :scale => 10
    t.decimal :lon, :precision => 15, :scale => 10
    t.timestamps
  end
  add_index :zipcodes, :code
  add_index :zipcodes, :county_id
  add_index :zipcodes, :state_id
  add_index :zipcodes, [:lat, :lon]

  # States Table
  create_table :states do |t|
    t.string :abbr, :limit => 2
    t.string :name
    t.timestamps
  end
  add_index :states, :abbr

  # Counties Table
  create_table :counties do |t|
    t.integer :state_id
    t.string :abbr
    t.string :name
    t.string :county_seat
    t.timestamps
  end
  add_index :counties, :name
  add_index :counties, :state_id
end