diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-01-13 16:01:51 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-01-13 16:01:51 -0500 |
commit | 7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6 (patch) | |
tree | d2e020ca045ce3d6f28a6d912bbc343db03265d2 /db | |
parent | d91e1d9a9ee98cc364bc62a4dd156500a189b99a (diff) | |
download | pokeviewer-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')
-rw-r--r-- | db/migrate/20180113200119_move_species_to_revision.rb | 39 |
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 @@ | |||
1 | class 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 | ||
39 | end | ||