diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-19 17:16:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-19 17:16:28 +0300 |
commit | e4384360a16dd9a19d4d2d25d0ef1f2b862ed2a6 (patch) | |
tree | 2fcdfa7dcdb9db8f5208b2562f4b4e803d671243 /db/post_migrate/20230615030402_remove_audit_events_group_index.rb | |
parent | ffda4e7bcac36987f936b4ba515995a6698698f0 (diff) |
Add latest changes from gitlab-org/gitlab@16-2-stable-eev16.2.0-rc42
Diffstat (limited to 'db/post_migrate/20230615030402_remove_audit_events_group_index.rb')
-rw-r--r-- | db/post_migrate/20230615030402_remove_audit_events_group_index.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/db/post_migrate/20230615030402_remove_audit_events_group_index.rb b/db/post_migrate/20230615030402_remove_audit_events_group_index.rb new file mode 100644 index 00000000000..9a77d7a4d0d --- /dev/null +++ b/db/post_migrate/20230615030402_remove_audit_events_group_index.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveAuditEventsGroupIndex < Gitlab::Database::Migration[2.1] + include Gitlab::Database::PartitioningMigrationHelpers + + TABLE_NAME = :audit_events + COLUMN_NAMES = [:entity_id, :entity_type, :created_at, :id] + INDEX_NAME = 'index_audit_events_on_entity_id_and_entity_type_and_created_at' + + # TODO: Index to be destroyed synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/415424 + def up + each_partition(TABLE_NAME) do |partition, partition_index_name| + unprepare_async_index_by_name(partition.identifier, partition_index_name) + end + end + + def down + each_partition(TABLE_NAME) do |partition, partition_index_name| + prepare_async_index( + partition.identifier, + COLUMN_NAMES, + name: 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 |