diff options
Diffstat (limited to 'db/post_migrate/20231004091113_swap_columns_for_ci_sources_pipelines_pipeline_id_bigint.rb')
-rw-r--r-- | db/post_migrate/20231004091113_swap_columns_for_ci_sources_pipelines_pipeline_id_bigint.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/db/post_migrate/20231004091113_swap_columns_for_ci_sources_pipelines_pipeline_id_bigint.rb b/db/post_migrate/20231004091113_swap_columns_for_ci_sources_pipelines_pipeline_id_bigint.rb index 6ce4e1a4da5..d7b274be29f 100644 --- a/db/post_migrate/20231004091113_swap_columns_for_ci_sources_pipelines_pipeline_id_bigint.rb +++ b/db/post_migrate/20231004091113_swap_columns_for_ci_sources_pipelines_pipeline_id_bigint.rb @@ -36,6 +36,8 @@ class SwapColumnsForCiSourcesPipelinesPipelineIdBigint < Gitlab::Database::Migra private def swap + ensure_indexes_exist + with_lock_retries(raise_on_exhaustion: true) do # Lock the tables involved. execute "LOCK TABLE #{TARGET_TABLE_NAME}, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" @@ -74,4 +76,14 @@ class SwapColumnsForCiSourcesPipelinesPipelineIdBigint < Gitlab::Database::Migra end end end + + def ensure_indexes_exist + unless index_exists?(TABLE_NAME, :pipeline_id, name: :index_ci_sources_pipelines_on_pipeline_id) + add_concurrent_index(TABLE_NAME, :pipeline_id, name: :index_ci_sources_pipelines_on_pipeline_id) + end + + return if index_exists?(TABLE_NAME, :source_pipeline_id, name: :index_ci_sources_pipelines_on_source_pipeline_id) + + add_concurrent_index(TABLE_NAME, :source_pipeline_id, name: :index_ci_sources_pipelines_on_source_pipeline_id) + end end |