Commit 640e19a7 authored by Patrick Bair's avatar Patrick Bair

Merge branch '345993-prepare-deleted-records-table-to-sliding-partitioning' into 'master'

Prepare loose FK table for sliding partitioning

See merge request gitlab-org/gitlab!74796
parents 615985fe 991aaee6
# frozen_string_literal: true
class ChangeDefaultValueOfLooseFkDeletedRecordsPartition < Gitlab::Database::Migration[1.0]
enable_lock_retries!
def change
change_column_default(:loose_foreign_keys_deleted_records, :partition, from: nil, to: 1)
end
end
# frozen_string_literal: true
class RemoveHardcodedPartitionFromLooseFkTriggerFunction < Gitlab::Database::Migration[1.0]
include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
enable_lock_retries!
def up
execute(<<~SQL)
CREATE OR REPLACE FUNCTION #{DELETED_RECORDS_INSERT_FUNCTION_NAME}()
RETURNS TRIGGER AS
$$
BEGIN
INSERT INTO loose_foreign_keys_deleted_records
(fully_qualified_table_name, primary_key_value)
SELECT TG_TABLE_SCHEMA || '.' || TG_TABLE_NAME, old_table.id FROM old_table;
RETURN NULL;
END
$$ LANGUAGE PLPGSQL
SQL
end
def down
execute(<<~SQL)
CREATE OR REPLACE FUNCTION #{DELETED_RECORDS_INSERT_FUNCTION_NAME}()
RETURNS TRIGGER AS
$$
BEGIN
INSERT INTO loose_foreign_keys_deleted_records
(partition, fully_qualified_table_name, primary_key_value)
SELECT 1, TG_TABLE_SCHEMA || '.' || TG_TABLE_NAME, old_table.id FROM old_table
ON CONFLICT DO NOTHING;
RETURN NULL;
END
$$ LANGUAGE PLPGSQL
SQL
end
end
8b1bb9758150151518f16307d3f145431000b7edf946fd44e54cf7301087b002
\ No newline at end of file
721f1ada9fe5a3d7e5da3750a43d5021a85a26e8adc4d649e7f0fff8cdf68344
\ No newline at end of file
......@@ -27,9 +27,8 @@ CREATE FUNCTION insert_into_loose_foreign_keys_deleted_records() RETURNS trigger
AS $$
BEGIN
INSERT INTO loose_foreign_keys_deleted_records
(partition, fully_qualified_table_name, primary_key_value)
SELECT 1, TG_TABLE_SCHEMA || '.' || TG_TABLE_NAME, old_table.id FROM old_table
ON CONFLICT DO NOTHING;
(fully_qualified_table_name, primary_key_value)
SELECT TG_TABLE_SCHEMA || '.' || TG_TABLE_NAME, old_table.id FROM old_table;
RETURN NULL;
END
......@@ -1016,7 +1015,7 @@ ALTER TABLE ONLY analytics_cycle_analytics_merge_request_stage_events ATTACH PAR
CREATE TABLE loose_foreign_keys_deleted_records (
id bigint NOT NULL,
partition bigint NOT NULL,
partition bigint DEFAULT 1 NOT NULL,
primary_key_value bigint NOT NULL,
status smallint DEFAULT 1 NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
......@@ -1037,7 +1036,7 @@ ALTER SEQUENCE loose_foreign_keys_deleted_records_id_seq OWNED BY loose_foreign_
CREATE TABLE gitlab_partitions_static.loose_foreign_keys_deleted_records_1 (
id bigint DEFAULT nextval('loose_foreign_keys_deleted_records_id_seq'::regclass) NOT NULL,
partition bigint NOT NULL,
partition bigint DEFAULT 1 NOT NULL,
primary_key_value bigint NOT NULL,
status smallint DEFAULT 1 NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment