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

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

class ChangePrimaryKeyOfSecurityFindingsTable < Gitlab::Database::Migration[2.0]
  enable_lock_retries!

  def up
    execute(<<~SQL)
      ALTER TABLE security_findings DROP CONSTRAINT security_findings_pkey;
    SQL

    execute(<<~SQL)
      ALTER TABLE security_findings ADD CONSTRAINT security_findings_pkey PRIMARY KEY USING index security_findings_partitioned_pkey;
    SQL
  end

  def down
    execute(<<~SQL)
      ALTER TABLE security_findings DROP CONSTRAINT security_findings_pkey;
    SQL

    execute(<<~SQL)
      ALTER TABLE security_findings ADD CONSTRAINT security_findings_pkey PRIMARY KEY (id);
    SQL

    execute(<<~SQL)
      CREATE UNIQUE INDEX security_findings_partitioned_pkey ON security_findings USING btree(id, partition_number);
    SQL
  end
end