mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-14 21:24:54 +08:00
19 lines
605 B
Ruby
19 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
|