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