Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20201012073022_remove_not_null_constraint_on_framework.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b8cc8984575a895fb3453ffedabb11e87346803f (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
# frozen_string_literal: true

class RemoveNotNullConstraintOnFramework < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  GDPR_FRAMEWORK_ID = 1

  disable_ddl_transaction!

  class TmpComplianceProjectFrameworkSetting < ActiveRecord::Base
    self.table_name = 'project_compliance_framework_settings'
    self.primary_key = :project_id

    include EachBatch
  end

  def up
    change_column_null :project_compliance_framework_settings, :framework, true
  end

  def down
    # Custom frameworks cannot be rolled back easily since we don't have enum for them.
    # To make the database consistent, we mark them as GDPR framework.
    # Note: framework customization will be implemented in the next 1-3 releases so data
    # corruption due to the rollback is unlikely.
    TmpComplianceProjectFrameworkSetting.each_batch(of: 100) do |query|
      query.where(framework: nil).update_all(framework: GDPR_FRAMEWORK_ID)
    end

    change_column_null :project_compliance_framework_settings, :framework, false
  end
end