Commit af185ed0 authored by Jason Goodman's avatar Jason Goodman Committed by Patrick Bair

Add migration to update ultimate trial plan limits

Set ci_daily_pipeline_schedule_triggers to equal that of ultimate plan

Changelog: fixed
parent 1414d99d
# frozen_string_literal: true
class UpdateTrialPlansCiDailyPipelineScheduleTriggers < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
PREMIUM_TRIAL = 'premium_trial'
ULTIMATE_TRIAL = 'ultimate_trial'
EVERY_5_MINUTES = (1.day.in_minutes / 5).to_i
class Plan < ActiveRecord::Base
self.table_name = 'plans'
self.inheritance_column = :_type_disabled
has_one :limits, class_name: 'PlanLimits'
end
class PlanLimits < ActiveRecord::Base
self.table_name = 'plan_limits'
self.inheritance_column = :_type_disabled
belongs_to :plan
end
def plan_limits_present?
premium_trial_plan = Plan.find_by(name: PREMIUM_TRIAL)
ultimate_trial_plan = Plan.find_by(name: ULTIMATE_TRIAL)
premium_trial_plan && premium_trial_plan.limits && ultimate_trial_plan && ultimate_trial_plan.limits
end
def up
return unless Gitlab.dev_env_or_com?
if plan_limits_present?
create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', PREMIUM_TRIAL, EVERY_5_MINUTES)
create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', ULTIMATE_TRIAL, EVERY_5_MINUTES)
end
end
def down
return unless Gitlab.dev_env_or_com?
if plan_limits_present?
create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', PREMIUM_TRIAL, 0)
create_or_update_plan_limit('ci_daily_pipeline_schedule_triggers', ULTIMATE_TRIAL, 0)
end
end
end
a63f878d89269eb8a2a3cc3b0c81d700861031a079a4a69b56d45d73c4c7946e
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require_migration!('update_trial_plans_ci_daily_pipeline_schedule_triggers')
RSpec.describe UpdateTrialPlansCiDailyPipelineScheduleTriggers, :migration do
let!(:plans) { table(:plans) }
let!(:plan_limits) { table(:plan_limits) }
let!(:premium_trial_plan) { plans.create!(name: 'premium_trial', title: 'Premium Trial') }
let!(:ultimate_trial_plan) { plans.create!(name: 'ultimate_trial', title: 'Ultimate Trial') }
describe '#up' do
let!(:premium_trial_plan_limits) { plan_limits.create!(plan_id: premium_trial_plan.id, ci_daily_pipeline_schedule_triggers: 0) }
let!(:ultimate_trial_plan_limits) { plan_limits.create!(plan_id: ultimate_trial_plan.id, ci_daily_pipeline_schedule_triggers: 0) }
context 'when the environment is dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
end
it 'sets the trial plan limits for ci_daily_pipeline_schedule_triggers' do
disable_migrations_output { migrate! }
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
it 'does not change the plan limits if the ultimate trial plan is missing' do
ultimate_trial_plan.destroy!
expect { disable_migrations_output { migrate! } }.not_to change { plan_limits.count }
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
it 'does not change the plan limits if the ultimate trial plan limits is missing' do
ultimate_trial_plan_limits.destroy!
expect { disable_migrations_output { migrate! } }.not_to change { plan_limits.count }
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
it 'does not change the plan limits if the premium trial plan is missing' do
premium_trial_plan.destroy!
expect { disable_migrations_output { migrate! } }.not_to change { plan_limits.count }
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
it 'does not change the plan limits if the premium trial plan limits is missing' do
premium_trial_plan_limits.destroy!
expect { disable_migrations_output { migrate! } }.not_to change { plan_limits.count }
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
end
context 'when the environment is anything other than dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(false)
end
it 'does not update the plan limits' do
disable_migrations_output { migrate! }
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
end
end
describe '#down' do
let!(:premium_trial_plan_limits) { plan_limits.create!(plan_id: premium_trial_plan.id, ci_daily_pipeline_schedule_triggers: 288) }
let!(:ultimate_trial_plan_limits) { plan_limits.create!(plan_id: ultimate_trial_plan.id, ci_daily_pipeline_schedule_triggers: 288) }
context 'when the environment is dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
end
it 'sets the trial plan limits ci_daily_pipeline_schedule_triggers to zero' do
migrate_down!
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(0)
end
it 'does not change the plan limits if the ultimate trial plan is missing' do
ultimate_trial_plan.destroy!
expect { migrate_down! }.not_to change { plan_limits.count }
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
it 'does not change the plan limits if the ultimate trial plan limits is missing' do
ultimate_trial_plan_limits.destroy!
expect { migrate_down! }.not_to change { plan_limits.count }
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
it 'does not change the plan limits if the premium trial plan is missing' do
premium_trial_plan.destroy!
expect { migrate_down! }.not_to change { plan_limits.count }
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
it 'does not change the plan limits if the premium trial plan limits is missing' do
premium_trial_plan_limits.destroy!
expect { migrate_down! }.not_to change { plan_limits.count }
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
end
context 'when the environment is anything other than dev or com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(false)
end
it 'does not change the ultimate trial plan limits' do
migrate_down!
expect(ultimate_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
expect(premium_trial_plan_limits.reload.ci_daily_pipeline_schedule_triggers).to eq(288)
end
end
end
def migrate_down!
disable_migrations_output do
migrate!
described_class.new.down
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment