Commit 2951f5621b7c95b66b134a9c655d915459ae6a2c
1 parent
12fd7b75
Exists in
master
and in
2 other branches
Add migration to swap blocks between areas 2 and 3
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
1 changed file
with
32 additions
and
0 deletions
Show diff stats
db/migrate/20150904174335_swap_softwares_blocks_between_areas_2_and_3.rb
0 → 100644
@@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
1 | +class SwapSoftwaresBlocksBetweenAreas2And3 < ActiveRecord::Migration | ||
2 | + def up | ||
3 | + swap_software_blocks_between_areas_2_and_3 | ||
4 | + end | ||
5 | + | ||
6 | + def down | ||
7 | + swap_software_blocks_between_areas_2_and_3 | ||
8 | + end | ||
9 | + | ||
10 | + def swap_software_blocks_between_areas_2_and_3 | ||
11 | + Community.joins(:software_info).each do |software_community| | ||
12 | + print "." | ||
13 | + | ||
14 | + # Get areas 2 and 3 | ||
15 | + box_area_two = software_community.boxes.find_by_position 2 | ||
16 | + box_area_three = software_community.boxes.find_by_position 3 | ||
17 | + | ||
18 | + # Get all ids of blocks from areas 2 and 3 | ||
19 | + blocks_ids_from_area_two = box_area_two.blocks.select(:id).map(&:id) | ||
20 | + blocks_ids_from_area_three = box_area_three.blocks.select(:id).map(&:id) | ||
21 | + | ||
22 | + # Swap blocks from area 2 to 3 | ||
23 | + Block.update_all({:box_id=>box_area_three.id}, ["id IN (?)", blocks_ids_from_area_two]) | ||
24 | + | ||
25 | + # Swap blocks from area 3 to 2 | ||
26 | + Block.update_all({:box_id=>box_area_two.id}, ["id IN (?)", blocks_ids_from_area_three]) | ||
27 | + end | ||
28 | + | ||
29 | + puts "" | ||
30 | + end | ||
31 | +end | ||
32 | + |