about summary refs log tree commit diff stats
path: root/db/migrate/20171003154157_rename_pokemon_met_location.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20171003154157_rename_pokemon_met_location.rb')
-rw-r--r--db/migrate/20171003154157_rename_pokemon_met_location.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/db/migrate/20171003154157_rename_pokemon_met_location.rb b/db/migrate/20171003154157_rename_pokemon_met_location.rb new file mode 100644 index 0000000..4ccba57 --- /dev/null +++ b/db/migrate/20171003154157_rename_pokemon_met_location.rb
@@ -0,0 +1,30 @@
1class RenamePokemonMetLocation < ActiveRecord::Migration[5.1]
2 def up
3 add_column :pokeviewer_pokemon, :location_id, :integer, null: true
4
5 add_foreign_key :pokeviewer_pokemon, :pokeviewer_locations,
6 column: :location_id
7
8 Pokeviewer::Pokemon.all.each do |p|
9 unless p.met_location.nil?
10 p.location_id = p.met_location.to_i
11 p.save!
12 end
13 end
14
15 remove_column :pokeviewer_pokemon, :met_location
16 end
17
18 def down
19 add_column :pokeviewer_pokemon, :met_location, :string
20
21 Pokeviewer::Pokemon.all.each do |p|
22 unless p.location_id.nil?
23 p.met_location = p.location_id.to_s
24 p.save!
25 end
26 end
27
28 remove_column :pokeviewer_pokemon, :location_id
29 end
30end