socialforge/db/migrate/20161018082432_create_homep...

22 lines
467 B
Ruby

class CreateHomepages < ActiveRecord::Migration
def change
create_table :homepages do |t|
t.string :name
t.integer :article_id
t.references :user
t.timestamps
end
add_index :homepages, :user_id
count = User.all.count / 30 + 2
transaction do
for i in 1 ... count do i
User.page(i).per(30).each do |user|
Homepage.create(:user_id => user.id, :name => user.login)
end
end
end
end
end