blob: 8b94d4808d1f4cce9b3ba63a6f37476a3c31e5e9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
|