gitlab-org--gitlab-foss/app/models/concerns/issuable_states.rb

26 lines
831 B
Ruby
Raw Normal View History

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