From b618e52428bb659cb1fe3bdbe3d3763d48b4556c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 3 Oct 2017 15:11:00 -0400 Subject: Made "met location" into an actual association --- .../20171003154157_rename_pokemon_met_location.rb | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 db/migrate/20171003154157_rename_pokemon_met_location.rb (limited to 'db') 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 @@ +class RenamePokemonMetLocation < ActiveRecord::Migration[5.1] + def up + add_column :pokeviewer_pokemon, :location_id, :integer, null: true + + add_foreign_key :pokeviewer_pokemon, :pokeviewer_locations, + column: :location_id + + Pokeviewer::Pokemon.all.each do |p| + unless p.met_location.nil? + p.location_id = p.met_location.to_i + p.save! + end + end + + remove_column :pokeviewer_pokemon, :met_location + end + + def down + add_column :pokeviewer_pokemon, :met_location, :string + + Pokeviewer::Pokemon.all.each do |p| + unless p.location_id.nil? + p.met_location = p.location_id.to_s + p.save! + end + end + + remove_column :pokeviewer_pokemon, :location_id + end +end -- cgit 1.4.1