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-05-17 19:05:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 19:05:49 +0300
commit43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch)
treedceebdc68925362117480a5d672bcff122fb625b /db/post_migrate/20230220102212_swap_columns_ci_build_needs_big_int_conversion.rb
parent20c84b99005abd1c82101dfeff264ac50d2df211 (diff)
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'db/post_migrate/20230220102212_swap_columns_ci_build_needs_big_int_conversion.rb')
-rw-r--r--db/post_migrate/20230220102212_swap_columns_ci_build_needs_big_int_conversion.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/db/post_migrate/20230220102212_swap_columns_ci_build_needs_big_int_conversion.rb b/db/post_migrate/20230220102212_swap_columns_ci_build_needs_big_int_conversion.rb
new file mode 100644
index 00000000000..de98847fad4
--- /dev/null
+++ b/db/post_migrate/20230220102212_swap_columns_ci_build_needs_big_int_conversion.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+class SwapColumnsCiBuildNeedsBigIntConversion < Gitlab::Database::Migration[2.1]
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'ci_build_needs'
+
+ def up
+ return unless should_run?
+
+ swap
+ end
+
+ def down
+ return unless should_run?
+
+ swap
+ end
+
+ private
+
+ def should_run?
+ !Gitlab.jh? && (Gitlab.com? || Gitlab.dev_or_test_env?)
+ end
+
+ def swap
+ add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name:
+ 'index_ci_build_needs_on_id_convert_to_bigint'
+
+ with_lock_retries(raise_on_exhaustion: true) do
+ execute "LOCK TABLE #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
+
+ id_name = quote_column_name(:id)
+ temp_name = quote_column_name('id_tmp')
+ id_convert_to_bigint_name = quote_column_name(:id_convert_to_bigint)
+
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_name} TO #{temp_name}"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_convert_to_bigint_name} TO #{id_name}"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{temp_name} TO #{id_convert_to_bigint_name}"
+
+ function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(
+ TABLE_NAME, connection: Ci::ApplicationRecord.connection
+ ).name(
+ :id, :id_convert_to_bigint
+ )
+ execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
+
+ execute "ALTER SEQUENCE ci_build_needs_id_seq OWNED BY #{TABLE_NAME}.id"
+ change_column_default TABLE_NAME, :id, -> { "nextval('ci_build_needs_id_seq'::regclass)" }
+ change_column_default TABLE_NAME, :id_convert_to_bigint, 0
+
+ execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT ci_build_needs_pkey CASCADE"
+ rename_index TABLE_NAME, 'index_ci_build_needs_on_id_convert_to_bigint', 'ci_build_needs_pkey'
+ execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT ci_build_needs_pkey PRIMARY KEY USING INDEX ci_build_needs_pkey"
+ end
+ end
+end