class CacheCurrentPokemonRevision < ActiveRecord::Migration[5.1] def up change_table :pokemon do |t| t.references :current, null: true end add_foreign_key :pokemon, :revisions, column: :current_id Pokeviewer::Pokemon.all.each do |p| p.current_id = p.revisions.last.id p.save! end end def down remove_column :pokemon, :current_id end end