2019-02-14 13:33:26 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-02-11 12:48:37 -05:00
|
|
|
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
|
2019-02-14 13:33:26 -05:00
|
|
|
# and should be removed after the state column is removed.
|
2019-02-14 11:24:23 -05:00
|
|
|
# Check https://gitlab.com/gitlab-org/gitlab-ce/issues/51789 for more information
|
2019-02-12 13:39:56 -05:00
|
|
|
included do
|
|
|
|
before_save :set_state_id
|
|
|
|
end
|
|
|
|
|
2019-02-11 12:48:37 -05:00
|
|
|
def set_state_id
|
|
|
|
return if state.nil? || state.empty?
|
|
|
|
|
2019-02-14 13:33:26 -05:00
|
|
|
# Needed to prevent breaking some migration specs that
|
|
|
|
# rollback database to a point where state_id does not exist.
|
2019-02-14 13:37:12 -05:00
|
|
|
# We can use this guard clause for now since this file will
|
2019-03-28 10:31:14 -04:00
|
|
|
# be removed in the next release.
|
|
|
|
return unless self.has_attribute?(:state_id)
|
2019-02-14 13:33:26 -05:00
|
|
|
|
2019-03-28 10:31:14 -04:00
|
|
|
self.state_id = self.class.available_states[state]
|
2019-02-11 12:48:37 -05:00
|
|
|
end
|
|
|
|
end
|