24 lines
627 B
Ruby
24 lines
627 B
Ruby
|
class CreateSyllabusMembers < ActiveRecord::Migration
|
||
|
def change
|
||
|
create_table :syllabus_members do |t|
|
||
|
t.integer :rank
|
||
|
t.references :syllabus
|
||
|
t.references :user
|
||
|
|
||
|
t.timestamps
|
||
|
end
|
||
|
add_index :syllabus_members, :syllabus_id
|
||
|
add_index :syllabus_members, :user_id
|
||
|
add_index :syllabus_members, :rank
|
||
|
|
||
|
count = Syllabus.all.count / 30 + 2
|
||
|
transaction do
|
||
|
for i in 1 ... count do i
|
||
|
Syllabus.page(i).per(30).each do |syllabus|
|
||
|
SyllabusMember.create(:user_id => syllabus.user_id, :syllabus_id => syllabus.id, :rank => 1)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|