summaryrefslogtreecommitdiff
path: root/db/migrate/20221010184839_add_new_amount_used_to_ci_project_monthly_usages.rb
blob: 5c77dfe93344194c5452a415f8a47ec33e5d2f0a (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
# frozen_string_literal: true

class AddNewAmountUsedToCiProjectMonthlyUsages < Gitlab::Database::Migration[2.0]
  TABLE = :ci_project_monthly_usages
  OLD_COLUMN = :amount_used
  NEW_COLUMN = :new_amount_used
  TRIGGER_NAME = 'sync_projects_amount_used_columns'

  disable_ddl_transaction!

  def up
    check_trigger_permissions!(TABLE)

    add_column(TABLE, NEW_COLUMN, :decimal, default: 0.0, precision: 18, scale: 4, null: false, if_not_exists: true)

    install_rename_triggers(TABLE, OLD_COLUMN, NEW_COLUMN, trigger_name: TRIGGER_NAME)
  end

  def down
    remove_rename_triggers(TABLE, TRIGGER_NAME)

    remove_column(TABLE, NEW_COLUMN)
  end
end