Support async constraint validation for first list partition
What does this MR do and why?
See #393395 (closed). This is a MR to provide helpers to set the partition check constraint for new records and validate the constraint during weekend.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
- create a test table in
rails dbconsole
for bothgitlabhq_development
andgitlabhq_development_ci
:CREATE TABLE public.test_partitions ( id bigint NOT NULL, partition_id bigint DEFAULT 100 NOT NULL ); ALTER TABLE ONLY public.test_partitions ADD CONSTRAINT test_partitions_pkey PRIMARY KEY (id, partition_id);
- run
rails g migration test_partition_constraint_validation
- edit the migration file
class TestPartitionConstraintValidation < Gitlab::Database::Migration[2.1] include Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers disable_ddl_transaction! def up prepare_constraint_for_list_partitioning( table_name: :test_partitions, partitioning_column: :partition_id, parent_table_name: :p_test_partitions, initial_partitioning_value: 100, async: true ) end def down # do nothing end end
- run the migration
rails db:migrate
- check if the table has the partition constraint in Rails dbconsole:
\d public.test_partitions;
- check if the async partition constraint validation is created in Rails console:
Gitlab::Database::AsyncConstraints::PostgresAsyncConstraintValidation.check_constraint_type.last
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #393395 (closed)
Edited by Tianwen Chen