scinote-web/db/migrate/20150730090021_add_my_module_groups_to_project.rb

19 lines
610 B
Ruby
Raw Normal View History

2017-06-30 16:23:28 +08:00
class AddMyModuleGroupsToProject < ActiveRecord::Migration[4.2]
2016-02-12 23:52:43 +08:00
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