about summary refs log tree commit diff stats
path: root/db/migrate/20180113211911_move_species_to_revision.pokeviewer.rb
blob: bd19f214331a58a57a6db7a534b38794288508bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #0000
# This migration comes from pokeviewer (originally 20180113200119)
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