diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20210503221405_create_locations.rb | 15 | ||||
-rw-r--r-- | db/schema.rb | 14 | ||||
-rw-r--r-- | db/seeds.rb | 13 |
3 files changed, 37 insertions, 5 deletions
diff --git a/db/migrate/20210503221405_create_locations.rb b/db/migrate/20210503221405_create_locations.rb new file mode 100644 index 0000000..83bd143 --- /dev/null +++ b/db/migrate/20210503221405_create_locations.rb @@ -0,0 +1,15 @@ +class CreateLocations < ActiveRecord::Migration[6.1] + def change + create_table :locations do |t| + t.string :gid + t.string :name + t.text :description + t.jsonb :whatnot + + t.timestamps + end + + add_index :locations, :gid + add_reference :activities, :location + end +end diff --git a/db/schema.rb b/db/schema.rb index 8dd6dcc..bddf880 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_05_03_215828) do +ActiveRecord::Schema.define(version: 2021_05_03_221405) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -22,7 +22,9 @@ ActiveRecord::Schema.define(version: 2021_05_03_215828) do t.jsonb "whatnot" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.bigint "location_id" t.index ["gid"], name: "index_activities_on_gid" + t.index ["location_id"], name: "index_activities_on_location_id" end create_table "character_items", force: :cascade do |t| @@ -59,6 +61,16 @@ ActiveRecord::Schema.define(version: 2021_05_03_215828) do t.index ["gid"], name: "index_items_on_gid" end + create_table "locations", force: :cascade do |t| + t.string "gid" + t.string "name" + t.text "description" + t.jsonb "whatnot" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["gid"], name: "index_locations_on_gid" + end + create_table "skills", force: :cascade do |t| t.string "gid" t.string "name" diff --git a/db/seeds.rb b/db/seeds.rb index 00a0566..7fcd125 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -17,15 +17,20 @@ end load_data_file("data/items.yml").map do |gid, hash| item = Item.find_or_create_by(gid: gid) - item.name = hash[:name] - item.description = hash[:description] + item.assign_attributes(hash.except(:equip_slot, :usable)) item.equip_slot = hash[:equip_slot]&.to_sym item.usable = hash[:usable] || false - item.whatnot = hash[:whatnot] item.save end +load_data_file("data/locations.yml").map do |gid, hash| + location = Location.find_or_create_by(gid: gid) + location.update(hash) +end + load_data_file("data/activities.yml").map do |gid, hash| activity = Activity.find_or_create_by(gid: gid) - activity.update(hash) + activity.assign_attributes(hash.except(:location)) + activity.location = Location.find_by_gid(hash[:location]) + activity.save end |