Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20111027152724_issue_conten_to_note.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0677fee6b9736b9a09c9947b21436c755db08e5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class IssueContenToNote < ActiveRecord::Migration
  def up
    puts "Issue content is deprecated -> move to notes"
    Issue.find_each(:batch_size => 100) do |issue|
      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 "."
      else
        print "F"
      end
    end

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

    if total > 0
      puts "content of #{total} issues were not migrated"
    else
      puts "Done"
    end
  end

  def down
  end
end