From 6b5d069729ba713fee8e99cba209e445c397b5c4 Mon Sep 17 00:00:00 2001 From: Nikhil Vengal Date: Wed, 8 Oct 2025 00:07:36 -0700 Subject: [PATCH] Add alert model --- app/models/alert.rb | 2 ++ db/migrate/20251008063847_create_alerts.rb | 17 +++++++++++++++++ db/schema.rb | 16 +++++++++++++++- spec/models/alert_spec.rb | 5 +++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/models/alert.rb create mode 100644 db/migrate/20251008063847_create_alerts.rb create mode 100644 spec/models/alert_spec.rb diff --git a/app/models/alert.rb b/app/models/alert.rb new file mode 100644 index 0000000..9820d9e --- /dev/null +++ b/app/models/alert.rb @@ -0,0 +1,2 @@ +class Alert < ApplicationRecord +end diff --git a/db/migrate/20251008063847_create_alerts.rb b/db/migrate/20251008063847_create_alerts.rb new file mode 100644 index 0000000..a871eee --- /dev/null +++ b/db/migrate/20251008063847_create_alerts.rb @@ -0,0 +1,17 @@ +class CreateAlerts < ActiveRecord::Migration[8.0] + def change + create_table :alerts do |t| + t.string :category, null: false + t.text :description + t.string :park_code, null: false + t.string :title, null: false + t.string :url + t.timestamp :indexed_date + + t.timestamps + end + + add_index :alerts, :park_code + add_foreign_key :alerts, :parks, column: :park_code, primary_key: :code + end +end diff --git a/db/schema.rb b/db/schema.rb index a1e524f..3f84dea 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,19 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_10_08_044109) do +ActiveRecord::Schema[8.0].define(version: 2025_10_08_063847) do + create_table "alerts", force: :cascade do |t| + t.string "category", null: false + t.text "description" + t.string "park_code", null: false + t.string "title", null: false + t.string "url" + t.datetime "indexed_date" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["park_code"], name: "index_alerts_on_park_code" + end + create_table "parks", force: :cascade do |t| t.string "code", null: false t.string "name", null: false @@ -20,4 +32,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_10_08_044109) do t.datetime "updated_at", null: false t.index ["code"], name: "index_parks_on_code", unique: true end + + add_foreign_key "alerts", "parks", column: "park_code", primary_key: "code" end diff --git a/spec/models/alert_spec.rb b/spec/models/alert_spec.rb new file mode 100644 index 0000000..97a6d49 --- /dev/null +++ b/spec/models/alert_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Alert, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end