diff options
author | Sean McGivern <sean@gitlab.com> | 2019-04-02 08:39:53 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-04-02 08:39:53 +0000 |
commit | f87b7fe3b386962c45e83486634352da544857fb (patch) | |
tree | 4c3fc969e0306e9877d22f787e8064126bfdef75 /app | |
parent | 5ddd4f0f0708921ca0c8a9a941cfb4c0fb868b00 (diff) | |
parent | f2b7da4bf507691cffd419d3dd759fcf6311cdd6 (diff) | |
download | gitlab-ce-f87b7fe3b386962c45e83486634352da544857fb.tar.gz |
Merge branch 'issue_51789_part_1' into 'master'
Migrate issuable states to integer patch 1 of 2
Closes #51789
See merge request gitlab-org/gitlab-ce!25107
Diffstat (limited to 'app')
-rw-r--r-- | app/models/concerns/issuable.rb | 10 | ||||
-rw-r--r-- | app/models/concerns/issuable_states.rb | 25 | ||||
-rw-r--r-- | app/models/merge_request.rb | 4 |
3 files changed, 39 insertions, 0 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index c7ad182ab82..51a8395c013 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -23,6 +23,7 @@ module Issuable include Sortable include CreatedAtFilterable include UpdatedAtFilterable + include IssuableStates include ClosedAtFilterable # This object is used to gather issuable meta data for displaying @@ -143,6 +144,15 @@ module Issuable fuzzy_search(query, [:title]) end + # Available state values persisted in state_id column using state machine + # + # Override this on subclasses if different states are needed + # + # Check MergeRequest.available_states for example + def available_states + @available_states ||= { opened: 1, closed: 2 }.with_indifferent_access + end + # Searches for records with a matching title or description. # # This method uses ILIKE on PostgreSQL and LIKE on MySQL. diff --git a/app/models/concerns/issuable_states.rb b/app/models/concerns/issuable_states.rb new file mode 100644 index 00000000000..b722c541580 --- /dev/null +++ b/app/models/concerns/issuable_states.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module IssuableStates + extend ActiveSupport::Concern + + # The state:string column is being migrated to state_id:integer column + # This is a temporary hook to populate state_id column with new values + # and should be removed after the state column is removed. + # Check https://gitlab.com/gitlab-org/gitlab-ce/issues/51789 for more information + included do + before_save :set_state_id + end + + def set_state_id + return if state.nil? || state.empty? + + # Needed to prevent breaking some migration specs that + # rollback database to a point where state_id does not exist. + # We can use this guard clause for now since this file will + # be removed in the next release. + return unless self.has_attribute?(:state_id) + + self.state_id = self.class.available_states[state] + end +end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index f6b83453c2a..50e6391a700 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -210,6 +210,10 @@ class MergeRequest < ApplicationRecord '!' end + def self.available_states + @available_states ||= super.merge(merged: 3, locked: 4) + end + # Returns the top 100 target branches # # The returned value is a Array containing branch names |