From c9af398b8f242bdea590309f1bb22ad3e3a8cc1e Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 20 Oct 2015 14:36:50 -0400 Subject: [PATCH] Add new tables for stats --- app/models/stat.rb | 3 +++ app/models/stat_type.rb | 2 ++ .../20151020173640_create_stat_types.rb | 10 ++++++++ db/migrate/20151020183446_create_stats.rb | 13 ++++++++++ .../20151020183709_add_stats_to_cards.rb | 7 ++++++ db/migrate/20151020212018_fix_stat_columns.rb | 5 ++++ .../20151020212132_add_defaults_to_stats.rb | 8 +++++++ db/schema.rb | 24 ++++++++++++++++++- db/seeds.rb | 10 ++++++++ 9 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 app/models/stat.rb create mode 100644 app/models/stat_type.rb create mode 100644 db/migrate/20151020173640_create_stat_types.rb create mode 100644 db/migrate/20151020183446_create_stats.rb create mode 100644 db/migrate/20151020183709_add_stats_to_cards.rb create mode 100644 db/migrate/20151020212018_fix_stat_columns.rb create mode 100644 db/migrate/20151020212132_add_defaults_to_stats.rb diff --git a/app/models/stat.rb b/app/models/stat.rb new file mode 100644 index 0000000..008d95f --- /dev/null +++ b/app/models/stat.rb @@ -0,0 +1,3 @@ +class Stat < ActiveRecord::Base + belongs_to :state_type +end diff --git a/app/models/stat_type.rb b/app/models/stat_type.rb new file mode 100644 index 0000000..b056354 --- /dev/null +++ b/app/models/stat_type.rb @@ -0,0 +1,2 @@ +class StatType < ActiveRecord::Base +end diff --git a/db/migrate/20151020173640_create_stat_types.rb b/db/migrate/20151020173640_create_stat_types.rb new file mode 100644 index 0000000..252faf3 --- /dev/null +++ b/db/migrate/20151020173640_create_stat_types.rb @@ -0,0 +1,10 @@ +class CreateStatTypes < ActiveRecord::Migration + def change + create_table :stat_types do |t| + t.string :name + t.string :description + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151020183446_create_stats.rb b/db/migrate/20151020183446_create_stats.rb new file mode 100644 index 0000000..b5cafd0 --- /dev/null +++ b/db/migrate/20151020183446_create_stats.rb @@ -0,0 +1,13 @@ +class CreateStats < ActiveRecord::Migration + def change + create_table :stats do |t| + t.integer :min + t.integer :max + t.integer :awaken_min + t.integer :awaken_make + t.references :state_type, index: true, foreign_key: true + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151020183709_add_stats_to_cards.rb b/db/migrate/20151020183709_add_stats_to_cards.rb new file mode 100644 index 0000000..144d894 --- /dev/null +++ b/db/migrate/20151020183709_add_stats_to_cards.rb @@ -0,0 +1,7 @@ +class AddStatsToCards < ActiveRecord::Migration + def change + add_column :cards, :hp_stat_id, :integer + add_column :cards, :atk_stat_id, :integer + add_column :cards, :def_stat_id, :integer + end +end diff --git a/db/migrate/20151020212018_fix_stat_columns.rb b/db/migrate/20151020212018_fix_stat_columns.rb new file mode 100644 index 0000000..5bcfe08 --- /dev/null +++ b/db/migrate/20151020212018_fix_stat_columns.rb @@ -0,0 +1,5 @@ +class FixStatColumns < ActiveRecord::Migration + def change + rename_column :stats, :awaken_make, :awaken_max + end +end diff --git a/db/migrate/20151020212132_add_defaults_to_stats.rb b/db/migrate/20151020212132_add_defaults_to_stats.rb new file mode 100644 index 0000000..a12aace --- /dev/null +++ b/db/migrate/20151020212132_add_defaults_to_stats.rb @@ -0,0 +1,8 @@ +class AddDefaultsToStats < ActiveRecord::Migration + def change + change_column :stats, :min, :integer, default: 0 + change_column :stats, :max, :integer, default: 0 + change_column :stats, :awaken_min, :integer, default: 0 + change_column :stats, :awaken_max, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 22c3558..889ffc4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151014155435) do +ActiveRecord::Schema.define(version: 20151020212132) do create_table "awaken_types", force: :cascade do |t| t.string "name" @@ -33,6 +33,9 @@ ActiveRecord::Schema.define(version: 20151014155435) do t.datetime "updated_at", null: false t.integer "awaken_type_id" t.boolean "verified", default: false + t.integer "hp_stat_id" + t.integer "atk_stat_id" + t.integer "def_stat_id" end add_index "cards", ["awaken_type_id"], name: "index_cards_on_awaken_type_id" @@ -117,6 +120,25 @@ ActiveRecord::Schema.define(version: 20151014155435) do add_index "roles", ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id" add_index "roles", ["name"], name: "index_roles_on_name" + create_table "stat_types", force: :cascade do |t| + t.string "name" + t.string "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "stats", force: :cascade do |t| + t.integer "min", default: 0 + t.integer "max", default: 0 + t.integer "awaken_min", default: 0 + t.integer "awaken_max", default: 0 + t.integer "state_type_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "stats", ["state_type_id"], name: "index_stats_on_state_type_id" + create_table "super_attacks", force: :cascade do |t| t.string "name" t.string "description" diff --git a/db/seeds.rb b/db/seeds.rb index 5be4cb1..11dc24c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -19,6 +19,12 @@ awaken_types = [ 'Extreme', ] +stat_types = [ + ['HP', 'Health Points'], + ['ATK', 'Attack'], + ['DEF', 'Defense'], +] + roles = [ :admin, :moderator, @@ -41,3 +47,7 @@ end roles.each do |role| Role.where({ name: role }, without_protection: true).first_or_create end + +stat_types.each do |name, description| + StatType.create(name: name, description: description) +end