Created
September 29, 2015 17:08
-
-
Save codeadict/ac20285d1acdb1689f81 to your computer and use it in GitHub Desktop.
Rails migration that creates a table with all United States states and associated territories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddUsStates < ActiveRecord::Migration | |
def up | |
create_table :states do |t| | |
t.string :iso_abbr, unique: true | |
t.string :name | |
t.timestamps | |
end | |
#: insert states here | |
states_data = [ | |
{iso_abbr: "AL", name: "Alabama"}, | |
{iso_abbr: "AK", name: "Alaska"}, | |
{iso_abbr: "AS", name: "American Samoa"}, | |
{iso_abbr: "AZ", name: "Arizona"}, | |
{iso_abbr: "AR", name: "Arkansas"}, | |
{iso_abbr: "CA", name: "California"}, | |
{iso_abbr: "CO", name: "Colorado"}, | |
{iso_abbr: "CT", name: "Connecticut"}, | |
{iso_abbr: "DE", name: "Delaware"}, | |
{iso_abbr: "DC", name: "District of Columbia"}, | |
{iso_abbr: "FM", name: "Federated States of Micronesi"}, | |
{iso_abbr: "FL", name: "Florida"}, | |
{iso_abbr: "GA", name: "Georgia"}, | |
{iso_abbr: "GU", name: "Guam"}, | |
{iso_abbr: "HI", name: "Hawaii"}, | |
{iso_abbr: "ID", name: "Idaho"}, | |
{iso_abbr: "IL", name: "Illinois"}, | |
{iso_abbr: "IN", name: "Indiana"}, | |
{iso_abbr: "IA", name: "Iowa"}, | |
{iso_abbr: "KS", name: "Kansas"}, | |
{iso_abbr: "KY", name: "Kentucky"}, | |
{iso_abbr: "LA", name: "Louisiana"}, | |
{iso_abbr: "ME", name: "Maine"}, | |
{iso_abbr: "MH", name: "Marshall Islands"}, | |
{iso_abbr: "MD", name: "Maryland"}, | |
{iso_abbr: "MA", name: "Massachusetts"}, | |
{iso_abbr: "MI", name: "Michigan"}, | |
{iso_abbr: "MN", name: "Minnesota"}, | |
{iso_abbr: "MS", name: "Mississippi"}, | |
{iso_abbr: "MO", name: "Missouri"}, | |
{iso_abbr: "MT", name: "Montana"}, | |
{iso_abbr: "NE", name: "Nebraska"}, | |
{iso_abbr: "NV", name: "Nevada"}, | |
{iso_abbr: "NH", name: "New Hampshire"}, | |
{iso_abbr: "MJ", name: "New Jersey"}, | |
{iso_abbr: "NM", name: "New Mexico"}, | |
{iso_abbr: "NY", name: "New York"}, | |
{iso_abbr: "NC", name: "North Carolina"}, | |
{iso_abbr: "ND", name: "North Dakota"}, | |
{iso_abbr: "OH", name: "Ohio"}, | |
{iso_abbr: "OK", name: "Oklahoma"}, | |
{iso_abbr: "OR", name: "Oregon"}, | |
{iso_abbr: "PW", name: "Palau"}, | |
{iso_abbr: "PA", name: "Pennsylvania"}, | |
{iso_abbr: "PR", name: "Puerto Rico"}, | |
{iso_abbr: "RI", name: "Rhode Island"}, | |
{iso_abbr: "SC", name: "South Carolina"}, | |
{iso_abbr: "SD", name: "South Dakota"}, | |
{iso_abbr: "TN", name: "Tennessee"}, | |
{iso_abbr: "TX", name: "Texas"}, | |
{iso_abbr: "UT", name: "Utah"}, | |
{iso_abbr: "VT", name: "Vermont"}, | |
{iso_abbr: "VI", name: "Virgin Islands"}, | |
{iso_abbr: "VA", name: "Virginia"}, | |
{iso_abbr: "WA", name: "Washington"}, | |
{iso_abbr: "WV", name: "West Virginia"}, | |
{iso_abbr: "WI", name: "Wisconsin"}, | |
{iso_abbr: "WY", name: "Wyoming"}, | |
] | |
states = State.create(states_data) | |
end | |
def down | |
drop_table :states | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment