summaryrefslogtreecommitdiff
path: root/db/migrate/20200922075244_add_compliance_framework_model.rb
blob: 376482d9005a244eb4bf5be31bc168fb83eb439e (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
# frozen_string_literal: true

class AddComplianceFrameworkModel < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers
  DOWNTIME = false

  disable_ddl_transaction!

  def up
    unless table_exists?(:compliance_management_frameworks)
      with_lock_retries do
        create_table :compliance_management_frameworks do |t|
          t.references :group, foreign_key: { to_table: :namespaces, on_delete: :cascade }, null: false, index: false
          t.text :name, null: false
          t.text :description, null: false
          t.text :color, null: false
          t.index [:group_id, :name], unique: true
        end
      end
    end

    add_text_limit :compliance_management_frameworks, :name, 255
    add_text_limit :compliance_management_frameworks, :description, 255
    add_text_limit :compliance_management_frameworks, :color, 10
  end

  def down
    with_lock_retries do
      drop_table :compliance_management_frameworks
    end
  end
end