class CreateStates < ActiveRecord::Migration
def self.up
create_table :states do |t|
t.column :code, :string
t.column :description, :string
t.column :display_order, :integer
t.column :active, :boolean, :default => false
t.column :created_at, :string
t.column :updated_at, :string
end
State.create(:code => 'AL', :description => 'Alabama')
State.create(:code => 'AK', :description => 'Alaska')
State.create(:code => 'AZ', :description => 'Arizona')
State.create(:code => 'AR', :description => 'Arkansas')
State.create(:code => 'CA', :description => 'California')
State.create(:code => 'CO', :description => 'Colorado')
State.create(:code => 'CT', :description => 'Connecticut')
State.create(:code => 'DE', :description => 'Delaware')
State.create(:code => 'FL', :description => 'Florida')
State.create(:code => 'GA', :description => 'Georgia')
State.create(:code => 'HI', :description => 'Hawaii')
State.create(:code => 'ID', :description => 'Idaho')
State.create(:code => 'IL', :description => 'Illinois')
State.create(:code => 'IN', :description => 'Indiana')
State.create(:code => 'IA', :description => 'Iowa')
State.create(:code => 'KS', :description => 'Kansas')
State.create(:code => 'KY', :description => 'Kentucky')
State.create(:code => 'LA', :description => 'Louisiana')
State.create(:code => 'ME', :description => 'Maine')
State.create(:code => 'MD', :description => 'Maryland')
State.create(:code => 'MA', :description => 'Massachusetts')
State.create(:code => 'MI', :description => 'Michigan')
State.create(:code => 'MN', :description => 'Minnesota')
State.create(:code => 'MS', :description => 'Mississippi')
State.create(:code => 'MO', :description => 'Missouri')
State.create(:code => 'MT', :description => 'Montana')
State.create(:code => 'NE', :description => 'Nebraska')
State.create(:code => 'NV', :description => 'Nevada')
State.create(:code => 'NH', :description => 'New Hampshire')
State.create(:code => 'NJ', :description => 'New Jersey')
State.create(:code => 'NM', :description => 'New Mexico')
State.create(:code => 'NY', :description => 'New York')
State.create(:code => 'NC', :description => 'North Carolina')
State.create(:code => 'ND', :description => 'North Dakota')
State.create(:code => 'OH', :description => 'Ohio')
State.create(:code => 'OK', :description => 'Oklahoma')
State.create(:code => 'OR', :description => 'Oregon')
State.create(:code => 'PA', :description => 'Pennsylvania')
State.create(:code => 'RI', :description => 'Rhode Island')
State.create(:code => 'SC', :description => 'South Carolina')
State.create(:code => 'SD', :description => 'South Dakota')
State.create(:code => 'TN', :description => 'Tennessee')
State.create(:code => 'TX', :description => 'Texas')
State.create(:code => 'UT', :description => 'Utah')
State.create(:code => 'VT', :description => 'Vermont')
State.create(:code => 'VA', :description => 'Virginia')
State.create(:code => 'WA', :description => 'Washington')
State.create(:code => 'WV', :description => 'West Virginia')
State.create(:code => 'WI', :description => 'Wisconsin')
State.create(:code => 'WY', :description => 'Wyoming')
end
def self.down
drop_table :states
end
end
Saturday, April 28, 2007
States of the Union
I needed a lookup table of states and their abbreviations for my application so I rolled my own migration. I read data in from a CSV file and wrote these State.create statements into a new text file. If you need the same kind of table, maybe you can reuse what I did. Don't repeat yourself :)
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment