Add foreign key for ci_stages.pipeline_id_convert_to_bigint
What does this MR do and why?
This is to prepare the foreign key for ci_stages.pipeline_id_convert_to_bigint
- Create invalid foreign key in a regular migration. See https://docs.gitlab.com/ee/development/database/add_foreign_key_to_existing_column.html
- Prepare the async foreign key validation in post migration. See https://docs.gitlab.com/ee/development/database/add_foreign_key_to_existing_column.html#schedule-the-fk-to-be-validated
The required indexes are created, see the following output from postgres.ai:
Table "public.ci_stages"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
-------------------------------+-----------------------------+-----------+----------+---------------------------------------+----------+-------------+--------------+-------------
project_id | integer | | | | plain | | |
pipeline_id | integer | | | | plain | | |
created_at | timestamp without time zone | | | | plain | | |
updated_at | timestamp without time zone | | | | plain | | |
name | character varying | | | | extended | | |
status | integer | | | | plain | | |
lock_version | integer | | | 0 | plain | | |
position | integer | | | | plain | | |
id | bigint | | not null | nextval('ci_stages_id_seq'::regclass) | plain | | |
partition_id | bigint | | not null | | plain | | |
pipeline_id_convert_to_bigint | bigint | | | | plain | | |
Indexes:
"ci_stages_pkey" PRIMARY KEY, btree (id)
"index_ci_stages_on_pipeline_id" btree (pipeline_id)
"index_ci_stages_on_pipeline_id_and_id" btree (pipeline_id, id) WHERE status = ANY (ARRAY[0, 1, 2, 8, 9, 10])
"index_ci_stages_on_pipeline_id_and_name" UNIQUE, btree (pipeline_id, name)
"index_ci_stages_on_pipeline_id_and_position" btree (pipeline_id, "position")
"index_ci_stages_on_pipeline_id_convert_to_bigint" btree (pipeline_id_convert_to_bigint)
"index_ci_stages_on_pipeline_id_convert_to_bigint_and_id" btree (pipeline_id_convert_to_bigint, id) WHERE status = ANY (ARRAY[0, 1, 2, 8, 9, 10])
"index_ci_stages_on_pipeline_id_convert_to_bigint_and_name" UNIQUE, btree (pipeline_id_convert_to_bigint, name)
"index_ci_stages_on_pipeline_id_convert_to_bigint_and_position" btree (pipeline_id_convert_to_bigint, "position")
"index_ci_stages_on_project_id" btree (project_id)
Check constraints:
"check_81b431e49b" CHECK (lock_version IS NOT NULL)
Foreign-key constraints:
"fk_fb57e6cc56" FOREIGN KEY (pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE
Referenced by:
TABLE "p_ci_builds" CONSTRAINT "fk_3a9eaa254d" FOREIGN KEY (stage_id) REFERENCES ci_stages(id) ON DELETE CASCADE
Triggers:
trigger_07bc3c48f407 BEFORE INSERT OR UPDATE ON ci_stages FOR EACH ROW EXECUTE FUNCTION trigger_07bc3c48f407()
Access method: heap
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
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 #422814 (closed)
Edited by Tianwen Chen