From 7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 13 Jan 2018 16:01:51 -0500 Subject: Moved species from Pokémon to revision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The migration will set all of the revisions of each Pokémon to have the species that that Pokémon was set to. If reversed, the migration sets the Pokémon's species to the first revision's species, which mimics the behavior of the engine from before this change, but do note that running the migration backwards like this can lose data. This change slightly affects the loading time of the front page. See #2. refs #3 --- .../20180113200119_move_species_to_revision.rb | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 db/migrate/20180113200119_move_species_to_revision.rb (limited to 'db/migrate/20180113200119_move_species_to_revision.rb') 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 @@ +class MoveSpeciesToRevision < ActiveRecord::Migration[5.1] + def up + change_table :pokeviewer_revisions do |t| + t.references :species, null: true + end + + Pokeviewer::Revision.all.each do |r| + r.species_id = r.pokemon.species_id + r.save! + end + + remove_column :pokeviewer_pokemon, :species_id + + change_column_null :pokeviewer_revisions, :species_id, false + + add_foreign_key :pokeviewer_revisions, :pokeviewer_species, + column: :species_id + end + + def down + def up + change_table :pokeviewer_pokemon do |t| + t.references :species, null: true + end + + Pokeviewer::Pokemon.all.each do |p| + p.species_id = p.revisions.first.species_id + p.save! + end + + remove_column :pokeviewer_revisions, :species_id + + change_column_null :pokeviewer_pokemon, :species_id, false + + add_foreign_key :pokeviewer_pokemon, :pokeviewer_species, + column: :species_id + end + end +end -- cgit 1.4.1