summaryrefslogtreecommitdiff
path: root/db/migrate/20210602155056_add_merge_request_diff_commit_users.rb
blob: f99790e0ecae34842e1483511934ea30b8c055bd (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
# frozen_string_literal: true

class AddMergeRequestDiffCommitUsers < ActiveRecord::Migration[6.1]
  include Gitlab::Database::MigrationHelpers

  disable_ddl_transaction!

  def up
    create_table_with_constraints :merge_request_diff_commit_users, id: :bigint do |t|
      t.text :name
      t.text :email

      t.text_limit :name, 512
      t.text_limit :email, 512

      t.index [:name, :email], unique: true
    end

    # Names or Emails can be optional, so in some cases one of these may be
    # null. But if both are NULL/empty, no row should exist in this table.
    add_check_constraint(
      :merge_request_diff_commit_users,
      "(COALESCE(name, '') != '') OR (COALESCE(email, '') != '')",
      :merge_request_diff_commit_users_name_or_email_existence
    )
  end

  def down
    drop_table :merge_request_diff_commit_users
  end
end