To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / db / migrate / 007_create_journals.rb @ 441:cbce1fd3b1b7

History | View | Annotate | Download (2.32 KB)

1
class CreateJournals < ActiveRecord::Migration
2

    
3
  # model removed, but needed for data migration
4
  class IssueHistory < ActiveRecord::Base; belongs_to :issue; end
5
  # model removed
6
  class Permission < ActiveRecord::Base; end
7
  
8
  def self.up
9
    create_table :journals, :force => true do |t|
10
      t.column "journalized_id", :integer, :default => 0, :null => false
11
      t.column "journalized_type", :string, :limit => 30, :default => "", :null => false
12
      t.column "user_id", :integer, :default => 0, :null => false
13
      t.column "notes", :text
14
      t.column "created_on", :datetime, :null => false
15
    end
16
    create_table :journal_details, :force => true do |t|
17
      t.column "journal_id", :integer, :default => 0, :null => false
18
      t.column "property", :string, :limit => 30, :default => "", :null => false
19
      t.column "prop_key", :string, :limit => 30, :default => "", :null => false
20
      t.column "old_value", :string
21
      t.column "value", :string
22
    end
23
    
24
    # indexes
25
    add_index "journals", ["journalized_id", "journalized_type"], :name => "journals_journalized_id"
26
    add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id"
27
    
28
    Permission.create :controller => "issues", :action => "history", :description => "label_history", :sort => 1006, :is_public => true, :mail_option => 0, :mail_enabled => 0
29

    
30
    # data migration
31
    IssueHistory.find(:all, :include => :issue).each {|h|
32
      j = Journal.new(:journalized => h.issue, :user_id => h.author_id, :notes => h.notes, :created_on => h.created_on)
33
      j.details << JournalDetail.new(:property => 'attr', :prop_key => 'status_id', :value => h.status_id)
34
      j.save    
35
    }    
36

    
37
    drop_table :issue_histories
38
  end
39

    
40
  def self.down
41
    drop_table :journal_details
42
    drop_table :journals
43
    
44
    create_table "issue_histories", :force => true do |t|
45
      t.column "issue_id", :integer, :default => 0, :null => false
46
      t.column "status_id", :integer, :default => 0, :null => false
47
      t.column "author_id", :integer, :default => 0, :null => false
48
      t.column "notes", :text, :default => ""
49
      t.column "created_on", :timestamp
50
    end
51
  
52
    add_index "issue_histories", ["issue_id"], :name => "issue_histories_issue_id"
53

    
54
    Permission.find(:first, :conditions => ["controller=? and action=?", 'issues', 'history']).destroy
55
  end
56
end