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.

20150725112753_insert_allowed_statuses_for_new_issues.rb 1.2KB

1234567891011121314151617181920212223
  1. class InsertAllowedStatusesForNewIssues < ActiveRecord::Migration[4.2]
  2. def self.up
  3. # Adds the default status for all trackers and roles
  4. sql = "INSERT INTO #{WorkflowTransition.table_name} (tracker_id, old_status_id, new_status_id, role_id, type)" +
  5. " SELECT t.id, 0, t.default_status_id, r.id, 'WorkflowTransition'" +
  6. " FROM #{Tracker.table_name} t, #{Role.table_name} r"
  7. WorkflowTransition.connection.execute(sql)
  8. # Adds other statuses that are reachable with one transition
  9. # to preserve previous behaviour as default
  10. sql = "INSERT INTO #{WorkflowTransition.table_name} (tracker_id, old_status_id, new_status_id, role_id, type)" +
  11. " SELECT t.id, 0, w.new_status_id, w.role_id, 'WorkflowTransition'" +
  12. " FROM #{Tracker.table_name} t" +
  13. " JOIN #{IssueStatus.table_name} s on s.id = t.default_status_id" +
  14. " JOIN #{WorkflowTransition.table_name} w on w.tracker_id = t.id and w.old_status_id = s.id and w.type = 'WorkflowTransition'" +
  15. " WHERE w.new_status_id <> t.default_status_id"
  16. WorkflowTransition.connection.execute(sql)
  17. end
  18. def self.down
  19. WorkflowTransition.where(:old_status_id => 0).delete_all
  20. end
  21. end