summaryrefslogtreecommitdiff
path: root/db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
downloadgitlab-ce-1f5bd14001245a518cecb87d251dddcde78b9bfb.tar.gz
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb')
-rw-r--r--db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb b/db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb
new file mode 100644
index 00000000000..83dfe62ad71
--- /dev/null
+++ b/db/post_migrate/20230104150601_prepare_builds_metadata_async_idx.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+class PrepareBuildsMetadataAsyncIdx < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::PartitioningMigrationHelpers
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'p_ci_builds_metadata_on_runner_machine_id_idx'
+
+ def up
+ # Break up the logic from add_concurrent_partitioned_index so that the partition indices can be created async
+ # A follow-up migration will complete the index creation by creating the index on the metadata table, and
+ # creating the concurrent foreign key
+ each_partition(:p_ci_builds_metadata) do |partition, partition_index_name|
+ prepare_async_index(partition.identifier, :runner_machine_id,
+ name: partition_index_name, where: 'runner_machine_id IS NOT NULL')
+ end
+ end
+
+ def down
+ each_partition(:p_ci_builds_metadata) do |partition, partition_index_name|
+ unprepare_async_index_by_name(partition.identifier, partition_index_name)
+ end
+ end
+
+ private
+
+ def each_partition(table_name)
+ partitioned_table = find_partitioned_table(table_name)
+ partitioned_table.postgres_partitions.order(:name).each do |partition|
+ partition_index_name = generated_index_name(partition.identifier, INDEX_NAME)
+
+ yield partition, partition_index_name
+ end
+ end
+end