scinote-web/db/migrate/20150730090021_add_my_module_groups_to_project.rb
2016-02-12 16:52:43 +01:00

18 lines
605 B
Ruby

class AddMyModuleGroupsToProject < ActiveRecord::Migration
def change
add_column :my_module_groups, :project_id, :integer
# Update current module groups
MyModuleGroup.all.each do |my_module_group|
if my_module_group.my_modules.present? then
my_module_group.project_id = my_module_group.my_modules.first.project.id
my_module_group.save
end
end
# Now make column non-nullable
change_column :my_module_groups, :project_id, :integer, :null => false
add_foreign_key :my_module_groups, :projects
add_index :my_module_groups, :project_id
end
end