You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

007_create_journals.rb 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. class CreateJournals < ActiveRecord::Migration[4.2]
  2. # model removed, but needed for data migration
  3. class IssueHistory < ActiveRecord::Base; belongs_to :issue; end
  4. # model removed
  5. class Permission < ActiveRecord::Base; end
  6. def self.up
  7. create_table :journals, :force => true do |t|
  8. t.column "journalized_id", :integer, :default => 0, :null => false
  9. t.column "journalized_type", :string, :limit => 30, :default => "", :null => false
  10. t.column "user_id", :integer, :default => 0, :null => false
  11. t.column "notes", :text
  12. t.column "created_on", :datetime, :null => false
  13. end
  14. create_table :journal_details, :force => true do |t|
  15. t.column "journal_id", :integer, :default => 0, :null => false
  16. t.column "property", :string, :limit => 30, :default => "", :null => false
  17. t.column "prop_key", :string, :limit => 30, :default => "", :null => false
  18. t.column "old_value", :string
  19. t.column "value", :string
  20. end
  21. # indexes
  22. add_index "journals", ["journalized_id", "journalized_type"], :name => "journals_journalized_id"
  23. add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id"
  24. Permission.create :controller => "issues", :action => "history", :description => "label_history", :sort => 1006, :is_public => true, :mail_option => 0, :mail_enabled => 0
  25. # data migration
  26. IssueHistory.all.each {|h|
  27. j = Journal.new(:journalized => h.issue, :user_id => h.author_id, :notes => h.notes, :created_on => h.created_on)
  28. j.details << JournalDetail.new(:property => 'attr', :prop_key => 'status_id', :value => h.status_id)
  29. j.save
  30. }
  31. drop_table :issue_histories
  32. end
  33. def self.down
  34. drop_table :journal_details
  35. drop_table :journals
  36. create_table "issue_histories", :force => true do |t|
  37. t.column "issue_id", :integer, :default => 0, :null => false
  38. t.column "status_id", :integer, :default => 0, :null => false
  39. t.column "author_id", :integer, :default => 0, :null => false
  40. t.column "notes", :text, :default => ""
  41. t.column "created_on", :timestamp
  42. end
  43. add_index "issue_histories", ["issue_id"], :name => "issue_histories_issue_id"
  44. Permission.where("controller=? and action=?", 'issues', 'history').first.destroy
  45. end
  46. end