debian-mirror-gitlab/db/post_migrate/20211029102822_add_open_source_plan.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
870 B
Ruby
Raw Normal View History

2021-12-11 22:18:48 +05:30
# 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
2022-05-07 20:08:51 +05:30
return unless Gitlab.com?
2021-12-11 22:18:48 +05:30
opensource = Plan.create!(name: 'opensource', title: 'Open Source Program')
create_plan_limits('ultimate', opensource)
end
def down
2022-05-07 20:08:51 +05:30
return unless Gitlab.com?
2021-12-11 22:18:48 +05:30
Plan.where(name: 'opensource').delete_all
end
end