BigW Consortium Gitlab

20111027152724_issue_conten_to_note.rb 780 Bytes
Newer Older
gitlabhq committed
1 2
class IssueContenToNote < ActiveRecord::Migration
  def up
gitlabhq committed
3
    puts "Issue content is deprecated -> move to notes"
gitlabhq committed
4
    Issue.find_each(:batch_size => 100) do |issue|
gitlabhq committed
5 6 7 8 9 10 11 12 13 14 15 16 17
      next if issue.content.blank?
      note = Note.new(
        :note => issue.content,
        :project_id => issue.project_id,
        :noteable => issue,
        :created_at => issue.created_at,
        :updated_at => issue.created_at
      )
      note.author_id = issue.author_id

      if note.save
        issue.update_attributes(:content => nil)
        print "."
18
      else
gitlabhq committed
19 20 21 22 23 24
        print "F"
      end
    end

    total = Issue.where("content is not null").count

25 26 27
    if total > 0
      puts "content of #{total} issues were not migrated"
    else
gitlabhq committed
28
      puts "Done"
gitlabhq committed
29 30 31 32 33 34
    end
  end

  def down
  end
end