summaryrefslogtreecommitdiff
path: root/db/migrate/20220610140605_change_public_projects_cost_factor.rb
blob: cf0c275828c178bf54cbc1e09a723de78027ce5a (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
# frozen_string_literal: true

class ChangePublicProjectsCostFactor < Gitlab::Database::Migration[2.0]
  # This migration updates SaaS Runner cost factors for public projects.
  # Previously we had a disabled cost factor for public projects, meaning
  # that no CI minutes were counted by default. With a low cost factor
  # we count CI minutes consumption at a very low rate to prevent
  # abuses.
  disable_ddl_transaction!

  restrict_gitlab_migration gitlab_schema: :gitlab_ci

  DISABLED_COST_FACTOR = 0
  LOW_COST_FACTOR = 0.008

  class Runner < MigrationRecord
    self.table_name = 'ci_runners'

    scope :shared, -> { where(runner_type: 1) }
  end

  def up
    return unless Gitlab.com?

    Runner.shared.where(public_projects_minutes_cost_factor: DISABLED_COST_FACTOR)
      .update_all(public_projects_minutes_cost_factor: LOW_COST_FACTOR)
  end

  def down
    return unless Gitlab.com?

    Runner.shared.where(public_projects_minutes_cost_factor: LOW_COST_FACTOR)
      .update_all(public_projects_minutes_cost_factor: DISABLED_COST_FACTOR)
  end
end