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

20211005093558_add_range_partitioned_loose_fk_table.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6f52b6ec63b8a885ed5431a3f2a7c7ab99bf8d39 (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 AddRangePartitionedLooseFkTable < Gitlab::Database::Migration[1.0]
  include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers

  def up
    constraint_name = check_constraint_name('loose_foreign_keys_deleted_records', 'fully_qualified_table_name', 'max_length')
    execute(<<~SQL)
      CREATE TABLE loose_foreign_keys_deleted_records (
        id BIGSERIAL NOT NULL,
        partition bigint NOT NULL,
        primary_key_value bigint NOT NULL,
        status smallint NOT NULL DEFAULT 1,
        created_at timestamp with time zone NOT NULL DEFAULT NOW(),
        fully_qualified_table_name text NOT NULL,
        PRIMARY KEY (partition, id),
        CONSTRAINT #{constraint_name} CHECK ((char_length(fully_qualified_table_name) <= 150))
      ) PARTITION BY LIST (partition);

      CREATE TABLE gitlab_partitions_static.loose_foreign_keys_deleted_records_1
      PARTITION OF loose_foreign_keys_deleted_records
      FOR VALUES IN (1);
    SQL
  end

  def down
    drop_table :loose_foreign_keys_deleted_records
  end
end