Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20211029102822_add_open_source_plan.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bb65637ffcac4a1198475d01c51043167968fe69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

class AddOpenSourcePlan < Gitlab::Database::Migration[1.0]
  class Plan < ActiveRecord::Base
    self.inheritance_column = :_type_disabled

    has_one :limits, class_name: 'PlanLimits'

    def actual_limits
      self.limits || self.build_limits
    end
  end

  class PlanLimits < ActiveRecord::Base
    self.inheritance_column = :_type_disabled

    belongs_to :plan
  end

  def create_plan_limits(plan_limit_name, plan)
    plan_limit = Plan.find_or_initialize_by(name: plan_limit_name).actual_limits.dup
    plan_limit.plan = plan
    plan_limit.save!
  end

  def up
    return unless Gitlab.com?

    opensource = Plan.create!(name: 'opensource', title: 'Open Source Program')

    create_plan_limits('ultimate', opensource)
  end

  def down
    return unless Gitlab.com?

    Plan.where(name: 'opensource').delete_all
  end
end