diff options
Diffstat (limited to 'db/migrate/20180113211911_move_species_to_revision.pokeviewer.rb')
-rw-r--r-- | db/migrate/20180113211911_move_species_to_revision.pokeviewer.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/db/migrate/20180113211911_move_species_to_revision.pokeviewer.rb b/db/migrate/20180113211911_move_species_to_revision.pokeviewer.rb new file mode 100644 index 0000000..bd19f21 --- /dev/null +++ b/db/migrate/20180113211911_move_species_to_revision.pokeviewer.rb | |||
@@ -0,0 +1,40 @@ | |||
1 | # This migration comes from pokeviewer (originally 20180113200119) | ||
2 | class MoveSpeciesToRevision < ActiveRecord::Migration[5.1] | ||
3 | def up | ||
4 | change_table :pokeviewer_revisions do |t| | ||
5 | t.references :species, null: true | ||
6 | end | ||
7 | |||
8 | Pokeviewer::Revision.all.each do |r| | ||
9 | r.species_id = r.pokemon.species_id | ||
10 | r.save! | ||
11 | end | ||
12 | |||
13 | remove_column :pokeviewer_pokemon, :species_id | ||
14 | |||
15 | change_column_null :pokeviewer_revisions, :species_id, false | ||
16 | |||
17 | add_foreign_key :pokeviewer_revisions, :pokeviewer_species, | ||
18 | column: :species_id | ||
19 | end | ||
20 | |||
21 | def down | ||
22 | def up | ||
23 | change_table :pokeviewer_pokemon do |t| | ||
24 | t.references :species, null: true | ||
25 | end | ||
26 | |||
27 | Pokeviewer::Pokemon.all.each do |p| | ||
28 | p.species_id = p.revisions.first.species_id | ||
29 | p.save! | ||
30 | end | ||
31 | |||
32 | remove_column :pokeviewer_revisions, :species_id | ||
33 | |||
34 | change_column_null :pokeviewer_pokemon, :species_id, false | ||
35 | |||
36 | add_foreign_key :pokeviewer_pokemon, :pokeviewer_species, | ||
37 | column: :species_id | ||
38 | end | ||
39 | end | ||
40 | end | ||