Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-08-18 13:50:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-08-18 13:50:51 +0300
commitdb384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch)
tree34beaef37df5f47ccbcf5729d7583aae093cffa0 /db/post_migrate/20230718020825_swap_events_target_id_to_bigint_for_gitlab_dot_com.rb
parent54fd7b1bad233e3944434da91d257fa7f63c3996 (diff)
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'db/post_migrate/20230718020825_swap_events_target_id_to_bigint_for_gitlab_dot_com.rb')
-rw-r--r--db/post_migrate/20230718020825_swap_events_target_id_to_bigint_for_gitlab_dot_com.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/db/post_migrate/20230718020825_swap_events_target_id_to_bigint_for_gitlab_dot_com.rb b/db/post_migrate/20230718020825_swap_events_target_id_to_bigint_for_gitlab_dot_com.rb
new file mode 100644
index 00000000000..03e95e39649
--- /dev/null
+++ b/db/post_migrate/20230718020825_swap_events_target_id_to_bigint_for_gitlab_dot_com.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+class SwapEventsTargetIdToBigintForGitlabDotCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'events'
+
+ def up
+ return unless should_run?
+
+ swap
+ end
+
+ def down
+ return unless should_run?
+
+ swap
+ end
+
+ def swap
+ # This will replace the existing index_events_on_target_type_and_target_id_and_fingerprint
+ add_concurrent_index TABLE_NAME, [:target_type, :target_id_convert_to_bigint, :fingerprint],
+ name: :index_events_on_target_type_and_target_id_bigint_fingerprint,
+ unique: true
+
+ with_lock_retries(raise_on_exhaustion: true) do
+ execute "LOCK TABLE #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
+
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN target_id TO target_id_tmp"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN target_id_convert_to_bigint TO target_id"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN target_id_tmp TO target_id_convert_to_bigint"
+
+ function_name = Gitlab::Database::UnidirectionalCopyTrigger
+ .on_table(TABLE_NAME, connection: connection)
+ .name(:target_id, :target_id_convert_to_bigint)
+ execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
+
+ execute 'DROP INDEX IF EXISTS index_events_on_target_type_and_target_id_and_fingerprint'
+ rename_index TABLE_NAME, 'index_events_on_target_type_and_target_id_bigint_fingerprint',
+ 'index_events_on_target_type_and_target_id_and_fingerprint'
+ end
+ end
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end