diff options
Diffstat (limited to 'lib/gitlab/database/migrations/milestone_mixin.rb')
-rw-r--r-- | lib/gitlab/database/migrations/milestone_mixin.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/gitlab/database/migrations/milestone_mixin.rb b/lib/gitlab/database/migrations/milestone_mixin.rb new file mode 100644 index 00000000000..10bc0c192e7 --- /dev/null +++ b/lib/gitlab/database/migrations/milestone_mixin.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Gitlab + module Database + module Migrations + module MilestoneMixin + extend ActiveSupport::Concern + include Gitlab::ClassAttributes + + MilestoneNotSetError = Class.new(StandardError) + + class_methods do + def milestone(milestone_str = nil) + if milestone_str.present? + set_class_attribute(:migration_milestone, milestone_str) + else + get_class_attribute(:migration_milestone) + end + end + end + + def initialize(name = class_name, version = nil, type = nil) + raise MilestoneNotSetError, "Milestone is not set for #{self.class.name}" if milestone.nil? + + super(name, version) + @version = Gitlab::Database::Migrations::Version.new(version, milestone, type) + end + + def milestone # rubocop:disable Lint/DuplicateMethods + @milestone ||= self.class.milestone + end + end + end + end +end |