about summary refs log tree commit diff stats
path: root/db/migrate
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-01-13 16:01:51 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-01-13 16:01:51 -0500
commit7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6 (patch)
treed2e020ca045ce3d6f28a6d912bbc343db03265d2 /db/migrate
parentd91e1d9a9ee98cc364bc62a4dd156500a189b99a (diff)
downloadpokeviewer-7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6.tar.gz
pokeviewer-7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6.tar.bz2
pokeviewer-7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6.zip
Moved species from Pokémon to revision
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
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20180113200119_move_species_to_revision.rb39
1 files changed, 39 insertions, 0 deletions
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 @@
1class MoveSpeciesToRevision < ActiveRecord::Migration[5.1]
2 def up
3 change_table :pokeviewer_revisions do |t|
4 t.references :species, null: true
5 end
6
7 Pokeviewer::Revision.all.each do |r|
8 r.species_id = r.pokemon.species_id
9 r.save!
10 end
11
12 remove_column :pokeviewer_pokemon, :species_id
13
14 change_column_null :pokeviewer_revisions, :species_id, false
15
16 add_foreign_key :pokeviewer_revisions, :pokeviewer_species,
17 column: :species_id
18 end
19
20 def down
21 def up
22 change_table :pokeviewer_pokemon do |t|
23 t.references :species, null: true
24 end
25
26 Pokeviewer::Pokemon.all.each do |p|
27 p.species_id = p.revisions.first.species_id
28 p.save!
29 end
30
31 remove_column :pokeviewer_revisions, :species_id
32
33 change_column_null :pokeviewer_pokemon, :species_id, false
34
35 add_foreign_key :pokeviewer_pokemon, :pokeviewer_species,
36 column: :species_id
37 end
38 end
39end