From bafe2ca25dcb347bc00cbae5cb82d5658a92ec4f Mon Sep 17 00:00:00 2001 From: David Gay Date: Mon, 7 Jun 2021 20:25:56 -0400 Subject: Record and reference MonsterSpawn starting HP in the database --- db/migrate/20210608001838_add_starting_hp_to_monster_spawns.rb | 8 ++++++++ db/schema.rb | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210608001838_add_starting_hp_to_monster_spawns.rb (limited to 'db') diff --git a/db/migrate/20210608001838_add_starting_hp_to_monster_spawns.rb b/db/migrate/20210608001838_add_starting_hp_to_monster_spawns.rb new file mode 100644 index 0000000..4b89120 --- /dev/null +++ b/db/migrate/20210608001838_add_starting_hp_to_monster_spawns.rb @@ -0,0 +1,8 @@ +class AddStartingHpToMonsterSpawns < ActiveRecord::Migration[6.1] + def change + add_column :monster_spawns, :starting_hp, :integer + MonsterSpawn.all.each do |ms| + ms.update(starting_hp: ms.monster.max_hp) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6e34c95..9e062cb 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_06_06_215818) do +ActiveRecord::Schema.define(version: 2021_06_08_001838) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -211,6 +211,7 @@ ActiveRecord::Schema.define(version: 2021_06_06_215818) do t.bigint "location_id", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.integer "starting_hp" t.index ["location_id"], name: "index_monster_spawns_on_location_id" t.index ["monster_id"], name: "index_monster_spawns_on_monster_id" end -- cgit v1.2.3