diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/concerns/assignee_live_migration.rb | 20 | ||||
-rw-r--r-- | app/models/issue.rb | 7 |
2 files changed, 24 insertions, 3 deletions
diff --git a/app/models/concerns/assignee_live_migration.rb b/app/models/concerns/assignee_live_migration.rb new file mode 100644 index 00000000000..bf0fbc7a9d1 --- /dev/null +++ b/app/models/concerns/assignee_live_migration.rb @@ -0,0 +1,20 @@ +module AssigneeLiveMigration + # This method is a part of live migration concept. We need to migrate assignee_id + # to a separate table issue_assignees + def migrate_assignee + if assignee_needs_to_be_migrated? + Issue.transaction do + IssueAssignee.create(issue_id: id, user_id: assignee_id) + update(assignee_id: nil) + end + + return true + end + + false + end + + def assignee_needs_to_be_migrated? + assignee_id + end +end diff --git a/app/models/issue.rb b/app/models/issue.rb index ecfc33ec1a1..89e269f7872 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -9,6 +9,7 @@ class Issue < ActiveRecord::Base include Spammable include FasterCacheKeys include RelativePositioning + include AssigneeLiveMigration DueDateStruct = Struct.new(:title, :name).freeze NoDueDate = DueDateStruct.new('No Due Date', '0').freeze @@ -31,9 +32,9 @@ class Issue < ActiveRecord::Base scope :in_projects, ->(project_ids) { where(project_id: project_ids) } - scope :assigned, -> { where('EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id)') } - scope :unassigned, -> { where('NOT EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id)') } - scope :assigned_to, ->(u) { where('EXISTS (SELECT TRUE FROM issue_assignees WHERE user_id = ? AND issue_id = issues.id)', u.id)} + scope :assigned, -> { where('EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id) OR issues.assignee_id IS NOT NULL') } + scope :unassigned, -> { where('NOT EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id) OR issues.assignee_id IS NULL') } + scope :assigned_to, ->(u) { where('EXISTS (SELECT TRUE FROM issue_assignees WHERE user_id = :user_id AND issue_id = issues.id) OR issues.assignee_id = :user_id', user_id: u.id)} scope :without_due_date, -> { where(due_date: nil) } scope :due_before, ->(date) { where('issues.due_date < ?', date) } |