From 362b92dbebf1ccc529794890153f8c1bfc43637d Mon Sep 17 00:00:00 2001 From: David Gay Date: Sun, 11 Jul 2021 15:55:19 -0400 Subject: Give hearths a location --- app/models/hearth.rb | 1 + app/models/location.rb | 1 + db/migrate/20210711195205_add_location_to_hearth.rb | 9 +++++++++ db/schema.rb | 5 ++++- 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210711195205_add_location_to_hearth.rb diff --git a/app/models/hearth.rb b/app/models/hearth.rb index ee00c0c..cbd98dc 100644 --- a/app/models/hearth.rb +++ b/app/models/hearth.rb @@ -1,5 +1,6 @@ class Hearth < ApplicationRecord belongs_to :character + belongs_to :location has_many :built_hearth_amenities has_many :hearth_amenities, through: :built_hearth_amenities has_many :hearth_plantings diff --git a/app/models/location.rb b/app/models/location.rb index 7bd1386..e0aaf9b 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -3,6 +3,7 @@ class Location < ApplicationRecord has_many :activities has_many :characters + has_many :hearths has_many :monster_spawns validates :gid, :name, presence: true end diff --git a/db/migrate/20210711195205_add_location_to_hearth.rb b/db/migrate/20210711195205_add_location_to_hearth.rb new file mode 100644 index 0000000..c8031d6 --- /dev/null +++ b/db/migrate/20210711195205_add_location_to_hearth.rb @@ -0,0 +1,9 @@ +class AddLocationToHearth < ActiveRecord::Migration[6.1] + def change + add_reference :hearths, :location, foreign_key: true + Hearth.all.each do |hearth| + hearth.update(location: Location.find_by_gid("floret")) + end + change_column :hearths, :location_id, :bigint, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 3c6cc28..2263181 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.define(version: 2021_07_06_000053) do +ActiveRecord::Schema.define(version: 2021_07_11_195205) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -155,7 +155,9 @@ ActiveRecord::Schema.define(version: 2021_07_06_000053) do t.bigint "character_id", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.bigint "location_id", null: false t.index ["character_id"], name: "index_hearths_on_character_id" + t.index ["location_id"], name: "index_hearths_on_location_id" end create_table "item_infixes", force: :cascade do |t| @@ -332,6 +334,7 @@ ActiveRecord::Schema.define(version: 2021_07_06_000053) do add_foreign_key "hearth_plantings", "hearths" add_foreign_key "hearth_plantings", "items" add_foreign_key "hearths", "characters" + add_foreign_key "hearths", "locations" add_foreign_key "item_infixes", "characters" add_foreign_key "item_infixes", "items" add_foreign_key "item_infixes", "skills" -- cgit v1.2.3