# encoding: utf-8 class CreateArticleHomepages < ActiveRecord::Migration def change create_table :article_homepages do |t| t.string :title t.text :content t.references :user t.references :homepage t.timestamps end add_index :article_homepages, :user_id add_index :article_homepages, :homepage_id count = User.all.count / 30 + 2 transaction do for i in 1 ... count do i User.page(i).per(30).each do |user| if user.user_extensions && !user.user_extensions.description.nil? && user.user_extensions.description != "" article = ArticleHomepage.create(:user_id => user.id,:title => '个人简介', :content => user.user_extensions.description, :homepage_id => user.homepage.id) user.homepage.update_column('article_id', article.id) end end end end end end