From 50d72a8d0dbdcda374883d7ff1f897f1c4b02b7e Mon Sep 17 00:00:00 2001 From: Mark Nyon Date: Mon, 26 Feb 2024 06:04:41 -0500 Subject: [PATCH] Added state model (#7) --- app/models/state.rb | 3 + db/migrate/20240226103048_create_states.rb | 10 +++ db/schema.rb | 15 +++-- db/seeds.rb | 74 ++++++++++++++++++++++ spec/factories/states.rb | 5 ++ 5 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 app/models/state.rb create mode 100644 db/migrate/20240226103048_create_states.rb create mode 100644 spec/factories/states.rb diff --git a/app/models/state.rb b/app/models/state.rb new file mode 100644 index 0000000..949067c --- /dev/null +++ b/app/models/state.rb @@ -0,0 +1,3 @@ +class State < ApplicationRecord + +end diff --git a/db/migrate/20240226103048_create_states.rb b/db/migrate/20240226103048_create_states.rb new file mode 100644 index 0000000..aedae06 --- /dev/null +++ b/db/migrate/20240226103048_create_states.rb @@ -0,0 +1,10 @@ +class CreateStates < ActiveRecord::Migration[7.1] + def change + create_table :states, force: :cascade do |t| + t.string 'name' + t.string 'iso' + t.string 'ansi_code' + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 63881a1..df68ab8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -12,7 +10,16 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 0) do +ActiveRecord::Schema[7.1].define(version: 2024_02_26_103048) do # These are extensions that must be enabled in order to support this database - enable_extension 'plpgsql' + enable_extension "plpgsql" + + create_table "states", force: :cascade do |t| + t.string "name" + t.string "iso" + t.string "ansi_code" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + end diff --git a/db/seeds.rb b/db/seeds.rb index 07b11e8..1669264 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,3 +8,77 @@ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| # MovieGenre.find_or_create_by!(name: genre_name) # end +if State.count.zero? + puts 'Creating States...' + states = + [ + { ansi_code: 'AL', iso: 'US-AL', name: 'Alabama' }, + { ansi_code: 'AK', iso: 'US-AK', name: 'Alaska' }, + { ansi_code: 'AZ', iso: 'US-AZ', name: 'Arizona' }, + { ansi_code: 'AR', iso: 'US-AR', name: 'Arkansas' }, + { ansi_code: 'CA', iso: 'US-CA', name: 'California' }, + { ansi_code: 'CO', iso: 'US-CO', name: 'Colorado' }, + { ansi_code: 'CT', iso: 'US-CT', name: 'Connecticut' }, + { ansi_code: 'DE', iso: 'US-DE', name: 'Delaware' }, + { ansi_code: 'DC', iso: 'US-DC', name: 'District of Columbia' }, + { ansi_code: 'FL', iso: 'US-FL', name: 'Florida' }, + { ansi_code: 'GA', iso: 'US-GA', name: 'Georgia' }, + { ansi_code: 'HI', iso: 'US-HI', name: 'Hawaii' }, + { ansi_code: 'ID', iso: 'US-ID', name: 'Idaho' }, + { ansi_code: 'IL', iso: 'US-IL', name: 'Illinois' }, + { ansi_code: 'IN', iso: 'US-IN', name: 'Indiana' }, + { ansi_code: 'IA', iso: 'US-IA', name: 'Iowa' }, + { ansi_code: 'KS', iso: 'US-KS', name: 'Kansas' }, + { ansi_code: 'KY', iso: 'US-KY', name: 'Kentucky' }, + { ansi_code: 'LA', iso: 'US-LA', name: 'Louisiana' }, + { ansi_code: 'ME', iso: 'US-ME', name: 'Maine' }, + { ansi_code: 'MD', iso: 'US-MD', name: 'Maryland' }, + { ansi_code: 'MA', iso: 'US-MA', name: 'Massachusetts' }, + { ansi_code: 'MI', iso: 'US-MI', name: 'Michigan' }, + { ansi_code: 'MN', iso: 'US-MN', name: 'Minnesota' }, + { ansi_code: 'MS', iso: 'US-MS', name: 'Mississippi' }, + { ansi_code: 'MO', iso: 'US-MO', name: 'Missouri' }, + { ansi_code: 'MT', iso: 'US-MT', name: 'Montana' }, + { ansi_code: 'NE', iso: 'US-NE', name: 'Nebraska' }, + { ansi_code: 'NV', iso: 'US-NV', name: 'Nevada' }, + { ansi_code: 'NH', iso: 'US-NH', name: 'New Hampshire' }, + { ansi_code: 'NJ', iso: 'US-NJ', name: 'New Jersey' }, + { ansi_code: 'NM', iso: 'US-NM', name: 'New Mexico' }, + { ansi_code: 'NY', iso: 'US-NY', name: 'New York' }, + { ansi_code: 'NC', iso: 'US-NC', name: 'North Carolina' }, + { ansi_code: 'ND', iso: 'US-ND', name: 'North Dakota' }, + { ansi_code: 'OH', iso: 'US-OH', name: 'Ohio' }, + { ansi_code: 'OK', iso: 'US-OK', name: 'Oklahoma' }, + { ansi_code: 'OR', iso: 'US-OR', name: 'Oregon' }, + { ansi_code: 'PA', iso: 'US-PA', name: 'Pennsylvania' }, + { ansi_code: 'RI', iso: 'US-RI', name: 'Rhode Island' }, + { ansi_code: 'SC', iso: 'US-SC', name: 'South Carolina' }, + { ansi_code: 'SD', iso: 'US-SD', name: 'South Dakota' }, + { ansi_code: 'TN', iso: 'US-TN', name: 'Tennessee' }, + { ansi_code: 'TX', iso: 'US-TX', name: 'Texas' }, + { ansi_code: 'UT', iso: 'US-UT', name: 'Utah' }, + { ansi_code: 'VT', iso: 'US-VT', name: 'Vermont' }, + { ansi_code: 'VA', iso: 'US-VA', name: 'Virginia' }, + { ansi_code: 'WA', iso: 'US-WA', name: 'Washington' }, + { ansi_code: 'WV', iso: 'US-WV', name: 'West Virginia' }, + { ansi_code: 'WI', iso: 'US-WI', name: 'Wisconsin' }, + { ansi_code: 'WY', iso: 'US-WY', name: 'Wyoming' }, + { ansi_code: 'AB', iso: 'CA-AB', name: 'Alberta' }, + { ansi_code: 'BC', iso: 'CA-BC', name: 'British Columbia' }, + { ansi_code: 'MB', iso: 'CA-MB', name: 'Manitoba' }, + { ansi_code: 'NB', iso: 'CA-NB', name: 'New Brunswick' }, + { ansi_code: 'NL', iso: 'CA-NL', name: 'Newfoundland and Labrador' }, + { ansi_code: 'NS', iso: 'CA-NS', name: 'Nova Scotia' }, + { ansi_code: 'ON', iso: 'CA-ON', name: 'Ontario' }, + { ansi_code: 'PE', iso: 'CA-PE', name: 'Prince Edward Island' }, + { ansi_code: 'QC', iso: 'CA-QC', name: 'Quebec' }, + { ansi_code: 'SK', iso: 'CA-SK', name: 'Saskatchewan' }, + { ansi_code: 'NT', iso: 'CA-NT', name: 'Northwest Territories' }, + { ansi_code: 'NU', iso: 'CA-NU', name: 'Nunavut' }, + { ansi_code: 'YT', iso: 'CA-YT', name: 'Yukon Territory' } + ] + + states.each do |state| + State.create(state) + end +end diff --git a/spec/factories/states.rb b/spec/factories/states.rb new file mode 100644 index 0000000..848a1a6 --- /dev/null +++ b/spec/factories/states.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :state do + + end +end