diff options
-rw-r--r-- | app/models/pokeviewer/revision.rb | 33 | ||||
-rw-r--r-- | app/models/pokeviewer/revision_move.rb | 19 | ||||
-rw-r--r-- | db/migrate/20170917011258_create_pokeviewer_revision_moves.rb | 20 | ||||
-rw-r--r-- | db/migrate/20170917011258_create_pokeviewer_revisions.rb (renamed from db/migrate/20170917002857_create_pokeviewer_revisions.rb) | 20 | ||||
-rw-r--r-- | test/dummy/db/schema.rb | 24 |
5 files changed, 61 insertions, 55 deletions
diff --git a/app/models/pokeviewer/revision.rb b/app/models/pokeviewer/revision.rb index a8f8ab2..9d1ddf4 100644 --- a/app/models/pokeviewer/revision.rb +++ b/app/models/pokeviewer/revision.rb | |||
@@ -3,10 +3,6 @@ module Pokeviewer | |||
3 | belongs_to :pokemon | 3 | belongs_to :pokemon |
4 | acts_as_sequenced scope: :pokemon_id | 4 | acts_as_sequenced scope: :pokemon_id |
5 | 5 | ||
6 | has_many :revision_moves, -> { order "number ASC" } | ||
7 | has_many :moves, through: :revision_moves | ||
8 | |||
9 | validates :moves, presence: true | ||
10 | validates :nickname, presence: true | 6 | validates :nickname, presence: true |
11 | 7 | ||
12 | validates :experience, presence: true, | 8 | validates :experience, presence: true, |
@@ -68,5 +64,34 @@ module Pokeviewer | |||
68 | greater_than_or_equal_to: 0, | 64 | greater_than_or_equal_to: 0, |
69 | less_than_or_equal_to: 10, | 65 | less_than_or_equal_to: 10, |
70 | only_integer: true } | 66 | only_integer: true } |
67 | |||
68 | belongs_to :move_1, class_name: "Move" | ||
69 | belongs_to :move_2, class_name: "Move", optional: true | ||
70 | belongs_to :move_3, class_name: "Move", optional: true | ||
71 | belongs_to :move_4, class_name: "Move", optional: true | ||
72 | |||
73 | validates :move_1_pp_bonuses, presence: true, | ||
74 | numericality: { | ||
75 | greater_than_or_equal_to: 0, | ||
76 | less_than_or_equal_to: 3, | ||
77 | only_integer: true} | ||
78 | |||
79 | validates :move_2_pp_bonuses, presence: true, | ||
80 | numericality: { | ||
81 | greater_than_or_equal_to: 0, | ||
82 | less_than_or_equal_to: 3, | ||
83 | only_integer: true} | ||
84 | |||
85 | validates :move_3_pp_bonuses, presence: true, | ||
86 | numericality: { | ||
87 | greater_than_or_equal_to: 0, | ||
88 | less_than_or_equal_to: 3, | ||
89 | only_integer: true} | ||
90 | |||
91 | validates :move_4_pp_bonuses, presence: true, | ||
92 | numericality: { | ||
93 | greater_than_or_equal_to: 0, | ||
94 | less_than_or_equal_to: 3, | ||
95 | only_integer: true} | ||
71 | end | 96 | end |
72 | end | 97 | end |
diff --git a/app/models/pokeviewer/revision_move.rb b/app/models/pokeviewer/revision_move.rb deleted file mode 100644 index 74b9e9e..0000000 --- a/app/models/pokeviewer/revision_move.rb +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | module Pokeviewer | ||
2 | class RevisionMove < ApplicationRecord | ||
3 | belongs_to :revision | ||
4 | belongs_to :move | ||
5 | |||
6 | validates :number, presence: true, | ||
7 | numericality: { | ||
8 | greater_than_or_equal_to: 1, | ||
9 | less_than_or_equal_to: 4, | ||
10 | only_integer: true }, | ||
11 | uniqueness: { scope: :revision_id } | ||
12 | |||
13 | validates :pp_bonuses, presence: true, | ||
14 | numericality: { | ||
15 | greater_than_or_equal_to: 0, | ||
16 | less_than_or_equal_to: 3, | ||
17 | only_integer: true} | ||
18 | end | ||
19 | end | ||
diff --git a/db/migrate/20170917011258_create_pokeviewer_revision_moves.rb b/db/migrate/20170917011258_create_pokeviewer_revision_moves.rb deleted file mode 100644 index e061207..0000000 --- a/db/migrate/20170917011258_create_pokeviewer_revision_moves.rb +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | class CreatePokeviewerRevisionMoves < ActiveRecord::Migration[5.1] | ||
2 | def change | ||
3 | create_table :pokeviewer_revision_moves do |t| | ||
4 | t.references :revision, null: false | ||
5 | t.references :move, null: false | ||
6 | t.integer :number, null: false | ||
7 | t.integer :pp_bonuses, null: false, default: 0 | ||
8 | |||
9 | t.timestamps | ||
10 | end | ||
11 | |||
12 | add_index :pokeviewer_revision_moves, [:revision_id, :number], unique: true | ||
13 | |||
14 | add_foreign_key :pokeviewer_revision_moves, :pokeviewer_revisions, | ||
15 | column: :revision_id | ||
16 | |||
17 | add_foreign_key :pokeviewer_revision_moves, :pokeviewer_moves, | ||
18 | column: :move_id | ||
19 | end | ||
20 | end | ||
diff --git a/db/migrate/20170917002857_create_pokeviewer_revisions.rb b/db/migrate/20170917011258_create_pokeviewer_revisions.rb index f6755da..faa3532 100644 --- a/db/migrate/20170917002857_create_pokeviewer_revisions.rb +++ b/db/migrate/20170917011258_create_pokeviewer_revisions.rb | |||
@@ -19,6 +19,14 @@ class CreatePokeviewerRevisions < ActiveRecord::Migration[5.1] | |||
19 | t.integer :toughness, null: false | 19 | t.integer :toughness, null: false |
20 | t.integer :sheen, null: false | 20 | t.integer :sheen, null: false |
21 | t.integer :hold_item, null: true | 21 | t.integer :hold_item, null: true |
22 | t.references :move_1, null: false | ||
23 | t.references :move_2, null: true | ||
24 | t.references :move_3, null: true | ||
25 | t.references :move_4, null: true | ||
26 | t.integer :move_1_pp_bonuses, null: false, default: 0 | ||
27 | t.integer :move_2_pp_bonuses, null: false, default: 0 | ||
28 | t.integer :move_3_pp_bonuses, null: false, default: 0 | ||
29 | t.integer :move_4_pp_bonuses, null: false, default: 0 | ||
22 | 30 | ||
23 | t.timestamps | 31 | t.timestamps |
24 | end | 32 | end |
@@ -27,5 +35,17 @@ class CreatePokeviewerRevisions < ActiveRecord::Migration[5.1] | |||
27 | 35 | ||
28 | add_foreign_key :pokeviewer_revisions, :pokewalker_pokemon, | 36 | add_foreign_key :pokeviewer_revisions, :pokewalker_pokemon, |
29 | column: :pokemon_id | 37 | column: :pokemon_id |
38 | |||
39 | add_foreign_key :pokeviewer_revisions, :pokewalker_moves, | ||
40 | column: :move_1_id | ||
41 | |||
42 | add_foreign_key :pokeviewer_revisions, :pokewalker_moves, | ||
43 | column: :move_2_id | ||
44 | |||
45 | add_foreign_key :pokeviewer_revisions, :pokewalker_moves, | ||
46 | column: :move_3_id | ||
47 | |||
48 | add_foreign_key :pokeviewer_revisions, :pokewalker_moves, | ||
49 | column: :move_4_id | ||
30 | end | 50 | end |
31 | end | 51 | end |
diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 4b5ad80..ef8b1ae 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb | |||
@@ -43,18 +43,6 @@ ActiveRecord::Schema.define(version: 20170917011258) do | |||
43 | t.index ["uuid"], name: "index_pokeviewer_pokemon_on_uuid", unique: true | 43 | t.index ["uuid"], name: "index_pokeviewer_pokemon_on_uuid", unique: true |
44 | end | 44 | end |
45 | 45 | ||
46 | create_table "pokeviewer_revision_moves", force: :cascade do |t| | ||
47 | t.integer "revision_id", null: false | ||
48 | t.integer "move_id", null: false | ||
49 | t.integer "number", null: false | ||
50 | t.integer "pp_bonuses", default: 0, null: false | ||
51 | t.datetime "created_at", null: false | ||
52 | t.datetime "updated_at", null: false | ||
53 | t.index ["move_id"], name: "index_pokeviewer_revision_moves_on_move_id" | ||
54 | t.index ["revision_id", "number"], name: "index_pokeviewer_revision_moves_on_revision_id_and_number", unique: true | ||
55 | t.index ["revision_id"], name: "index_pokeviewer_revision_moves_on_revision_id" | ||
56 | end | ||
57 | |||
58 | create_table "pokeviewer_revisions", force: :cascade do |t| | 46 | create_table "pokeviewer_revisions", force: :cascade do |t| |
59 | t.integer "pokemon_id", null: false | 47 | t.integer "pokemon_id", null: false |
60 | t.integer "sequential_id", null: false | 48 | t.integer "sequential_id", null: false |
@@ -74,8 +62,20 @@ ActiveRecord::Schema.define(version: 20170917011258) do | |||
74 | t.integer "toughness", null: false | 62 | t.integer "toughness", null: false |
75 | t.integer "sheen", null: false | 63 | t.integer "sheen", null: false |
76 | t.integer "hold_item" | 64 | t.integer "hold_item" |
65 | t.integer "move_1_id", null: false | ||
66 | t.integer "move_2_id" | ||
67 | t.integer "move_3_id" | ||
68 | t.integer "move_4_id" | ||
69 | t.integer "move_1_pp_bonuses", default: 0, null: false | ||
70 | t.integer "move_2_pp_bonuses", default: 0, null: false | ||
71 | t.integer "move_3_pp_bonuses", default: 0, null: false | ||
72 | t.integer "move_4_pp_bonuses", default: 0, null: false | ||
77 | t.datetime "created_at", null: false | 73 | t.datetime "created_at", null: false |
78 | t.datetime "updated_at", null: false | 74 | t.datetime "updated_at", null: false |
75 | t.index ["move_1_id"], name: "index_pokeviewer_revisions_on_move_1_id" | ||
76 | t.index ["move_2_id"], name: "index_pokeviewer_revisions_on_move_2_id" | ||
77 | t.index ["move_3_id"], name: "index_pokeviewer_revisions_on_move_3_id" | ||
78 | t.index ["move_4_id"], name: "index_pokeviewer_revisions_on_move_4_id" | ||
79 | t.index ["pokemon_id", "sequential_id"], name: "index_pokeviewer_revisions_on_pokemon_id_and_sequential_id", unique: true | 79 | t.index ["pokemon_id", "sequential_id"], name: "index_pokeviewer_revisions_on_pokemon_id_and_sequential_id", unique: true |
80 | t.index ["pokemon_id"], name: "index_pokeviewer_revisions_on_pokemon_id" | 80 | t.index ["pokemon_id"], name: "index_pokeviewer_revisions_on_pokemon_id" |
81 | end | 81 | end |