Add index for partitioned PK on ci_stages

Step 2: https://docs.gitlab.com/ee/development/database/table_partitioning.html#step-2---create-required-indexes

Step 3: https://docs.gitlab.com/ee/development/database/table_partitioning.html#step-3---enforce-unique-constraint

Technical Proposal

Prepare Ci::Stage for partitioning, similar to what we did to partition Ci::BuildMetadata.

It creates asynchronous indexes required to partition this table:

Indexes:
    "ci_stages_pkey" PRIMARY KEY, btree (id)
    "index_ci_stages_on_pipeline_id_and_name" UNIQUE, btree (pipeline_id, name)
    "index_ci_stages_on_pipeline_id_convert_to_bigint_and_name" UNIQUE, btree (pipeline_id_convert_to_bigint, name)

Additionally create a synchronous index which will act as a no-op on gitlab.com.

You can follow the documentation to create those indexes locally.

Why are we doing this?

Those indexes will be used to partition ci_stages as explained in this MR introducing zero partition helper.

Edited by Panos Kanellidis