From 513f1334fb1618e1de682608f66e11ed371729ab Mon Sep 17 00:00:00 2001 From: Nikhil Vengal Date: Wed, 8 Oct 2025 08:08:00 -0700 Subject: [PATCH] Add parks_by_state model --- app/models/parks_by_state.rb | 2 ++ .../20251008150542_create_parks_by_states.rb | 14 ++++++++++++++ db/schema.rb | 12 +++++++++++- spec/models/parks_by_state_spec.rb | 4 ++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/models/parks_by_state.rb create mode 100644 db/migrate/20251008150542_create_parks_by_states.rb create mode 100644 spec/models/parks_by_state_spec.rb diff --git a/app/models/parks_by_state.rb b/app/models/parks_by_state.rb new file mode 100644 index 0000000..8dc4e37 --- /dev/null +++ b/app/models/parks_by_state.rb @@ -0,0 +1,2 @@ +class ParksByState < ApplicationRecord +end diff --git a/db/migrate/20251008150542_create_parks_by_states.rb b/db/migrate/20251008150542_create_parks_by_states.rb new file mode 100644 index 0000000..e2eacc9 --- /dev/null +++ b/db/migrate/20251008150542_create_parks_by_states.rb @@ -0,0 +1,14 @@ +class CreateParksByStates < ActiveRecord::Migration[8.0] + def change + create_table :parks_by_states do |t| + t.string :park_code, null: false + t.string :state, null: false + + t.timestamps + end + + add_index :parks_by_states, [:state, :park_code], unique: true + add_index :parks_by_states, :park_code + add_foreign_key :parks_by_states, :parks, column: :park_code, primary_key: :code + end +end diff --git a/db/schema.rb b/db/schema.rb index 712bdd4..02b27b9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_10_08_063847) do +ActiveRecord::Schema[8.0].define(version: 2025_10_08_150542) do create_table "alerts", force: :cascade do |t| t.string "category", null: false t.text "description" @@ -35,5 +35,15 @@ ActiveRecord::Schema[8.0].define(version: 2025_10_08_063847) do t.index ["code"], name: "index_parks_on_code", unique: true end + create_table "parks_by_states", force: :cascade do |t| + t.string "park_code", null: false + t.string "state", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["park_code"], name: "index_parks_by_states_on_park_code" + t.index ["state", "park_code"], name: "index_parks_by_states_on_state_and_park_code", unique: true + end + add_foreign_key "alerts", "parks", column: "park_code", primary_key: "code" + add_foreign_key "parks_by_states", "parks", column: "park_code", primary_key: "code" end diff --git a/spec/models/parks_by_state_spec.rb b/spec/models/parks_by_state_spec.rb new file mode 100644 index 0000000..fb6abe2 --- /dev/null +++ b/spec/models/parks_by_state_spec.rb @@ -0,0 +1,4 @@ +require 'rails_helper' + +RSpec.describe ParksByState, type: :model do +end