about summary refs log tree commit diff stats
path: root/db/migrate/20180114170238_cache_current_pokemon_revision.rb
blob: 8b1d6ff04a97e4219043781a8efb214a26b949d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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