From fce8bd402315bddfe3f6e71ea99fcff684d05d97 Mon Sep 17 00:00:00 2001 From: Aurélio A. Heckert Date: Wed, 26 Jun 2013 20:18:45 -0300 Subject: [PATCH] Migration to add ProductCategoriesBlock to all enterprises --- db/migrate/20130626152300_add_product_categories_block_to_enterprises.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+), 0 deletions(-) create mode 100644 db/migrate/20130626152300_add_product_categories_block_to_enterprises.rb diff --git a/db/migrate/20130626152300_add_product_categories_block_to_enterprises.rb b/db/migrate/20130626152300_add_product_categories_block_to_enterprises.rb new file mode 100644 index 0000000..9b6131c --- /dev/null +++ b/db/migrate/20130626152300_add_product_categories_block_to_enterprises.rb @@ -0,0 +1,18 @@ +class AddProductCategoriesBlockToEnterprises < ActiveRecord::Migration + def self.up + Enterprise.find_each do |enterprise| + enterprise.boxes << Box.new while enterprise.boxes.length < 2 + enterprise.boxes[1].blocks << ProductCategoriesBlock.new + end + end + + def self.down + Enterprise.find_each do |enterprise| + enterprise.boxes.each do |box| + box.blocks.each do |block| + block.destroy if block.class == ProductCategoriesBlock + end + end + end + end +end -- libgit2 0.21.2