diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /db/post_migrate/20211029102822_add_open_source_plan.rb | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'db/post_migrate/20211029102822_add_open_source_plan.rb')
-rw-r--r-- | db/post_migrate/20211029102822_add_open_source_plan.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/db/post_migrate/20211029102822_add_open_source_plan.rb b/db/post_migrate/20211029102822_add_open_source_plan.rb new file mode 100644 index 00000000000..00266640f03 --- /dev/null +++ b/db/post_migrate/20211029102822_add_open_source_plan.rb @@ -0,0 +1,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.dev_env_or_com? + + opensource = Plan.create!(name: 'opensource', title: 'Open Source Program') + + create_plan_limits('ultimate', opensource) + end + + def down + return unless Gitlab.dev_env_or_com? + + Plan.where(name: 'opensource').delete_all + end +end |