diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20210711195205_add_location_to_hearth.rb | 9 | ||||
-rw-r--r-- | db/schema.rb | 5 | ||||
-rw-r--r-- | db/seeds.rb | 20 |
3 files changed, 25 insertions, 9 deletions
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" diff --git a/db/seeds.rb b/db/seeds.rb index 1e2888a..a513ee1 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -25,9 +25,11 @@ load_data_file("data/skills.yml").map do |gid, hash| skill.update(hash) end -load_data_file("data/items.yml").map do |gid, hash| - item = Item.find_or_create_by(gid: gid) - item.update(hash) +Dir["data/items/*"].each do |file_name| + load_data_file(file_name).map do |gid, hash| + item = Item.find_or_create_by(gid: gid) + item.update(hash) + end end load_data_file("data/locations.yml").map do |gid, hash| @@ -35,11 +37,13 @@ load_data_file("data/locations.yml").map do |gid, hash| location.update(hash) end -load_data_file("data/activities.yml").map do |gid, hash| - activity = Activity.find_or_create_by(gid: gid) - activity.assign_attributes(hash.except(:location)) - activity.location = Location.find_by_gid(hash[:location]) - activity.save +Dir["data/activities/*"].each do |file_name| + load_data_file(file_name).map do |gid, hash| + activity = Activity.find_or_create_by(gid: gid) + activity.assign_attributes(hash.except(:location)) + activity.location = Location.find_by_gid(hash[:location]) + activity.save + end end load_data_file("data/hearth_amenities.yml").map do |gid, hash| |