cirandas.net

ref: master

db/migrate/20150423144533_add_new_box_to_every_environment_and_profile.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class AddNewBoxToEveryEnvironmentAndProfile < ActiveRecord::Migration
    def up
      Environment.find_each do |env|
        env.boxes << Box.new if env.boxes.count < 4
      end

      Profile.find_each do |profile|
        profile.boxes << Box.new if profile.boxes.count < 4
      end
    end

    def down
      say "this migration can't be reverted"
    end
end