summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-21 21:08:28 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-21 21:08:28 +0000
commit0a93f691bf210da97fcefe0ddf80b38b0b186a99 (patch)
treecf17fdecf913d0576a4ec3eba0b3704c06c86470 /db/post_migrate
parent07d811cd3cf4d3a1802363532756bf69cfc6346f (diff)
downloadgitlab-ce-0a93f691bf210da97fcefe0ddf80b38b0b186a99.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20230419010332_ensure_todos_bigint_backfill_is_finished_for_gitlab_dot_com.rb29
-rw-r--r--db/post_migrate/20230419010551_add_index_todos_note_id_convert_to_bigint_for_gitlab_com.rb29
-rw-r--r--db/post_migrate/20230419012426_add_fk_on_todos_note_id_convert_to_bigint_for_gitlab_com.rb43
-rw-r--r--db/post_migrate/20230419012621_async_validate_fk_todos_note_id_convert_to_bigint_for_gitlab_com.rb27
4 files changed, 128 insertions, 0 deletions
diff --git a/db/post_migrate/20230419010332_ensure_todos_bigint_backfill_is_finished_for_gitlab_dot_com.rb b/db/post_migrate/20230419010332_ensure_todos_bigint_backfill_is_finished_for_gitlab_dot_com.rb
new file mode 100644
index 00000000000..d03fb0100e4
--- /dev/null
+++ b/db/post_migrate/20230419010332_ensure_todos_bigint_backfill_is_finished_for_gitlab_dot_com.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class EnsureTodosBigintBackfillIsFinishedForGitlabDotCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ def up
+ return unless should_run?
+
+ ensure_batched_background_migration_is_finished(
+ job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
+ table_name: 'todos',
+ column_name: 'id',
+ job_arguments: [['note_id'], ['note_id_convert_to_bigint']]
+ )
+ end
+
+ def down
+ # no-op
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230419010551_add_index_todos_note_id_convert_to_bigint_for_gitlab_com.rb b/db/post_migrate/20230419010551_add_index_todos_note_id_convert_to_bigint_for_gitlab_com.rb
new file mode 100644
index 00000000000..4ac5eeb5a14
--- /dev/null
+++ b/db/post_migrate/20230419010551_add_index_todos_note_id_convert_to_bigint_for_gitlab_com.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class AddIndexTodosNoteIdConvertToBigintForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = :todos
+ INDEX_NAME = :index_todos_on_note_id_convert_to_bigint
+
+ def up
+ return unless should_run?
+
+ # This will replace the existing index_todos_on_note_id
+ add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, name: INDEX_NAME
+ end
+
+ def down
+ return unless should_run?
+
+ remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230419012426_add_fk_on_todos_note_id_convert_to_bigint_for_gitlab_com.rb b/db/post_migrate/20230419012426_add_fk_on_todos_note_id_convert_to_bigint_for_gitlab_com.rb
new file mode 100644
index 00000000000..0cbab6f93da
--- /dev/null
+++ b/db/post_migrate/20230419012426_add_fk_on_todos_note_id_convert_to_bigint_for_gitlab_com.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+class AddFkOnTodosNoteIdConvertToBigintForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ SOURCE_TABLE_NAME = :todos
+ TARGET_TABLE_NAME = :notes
+ FK_NAME = :fk_todos_note_id_convert_to_bigint
+
+ def up
+ return unless should_run?
+
+ # This will replace the existing fk_91d1f47b13
+ # when we swap the integer and bigint columns
+ add_concurrent_foreign_key SOURCE_TABLE_NAME, TARGET_TABLE_NAME,
+ column: :note_id_convert_to_bigint,
+ name: FK_NAME,
+ on_delete: :cascade,
+ reverse_lock_order: true,
+ validate: false
+ end
+
+ def down
+ return unless should_run?
+
+ with_lock_retries do
+ remove_foreign_key_if_exists(
+ SOURCE_TABLE_NAME,
+ TARGET_TABLE_NAME,
+ name: FK_NAME,
+ reverse_lock_order: true
+ )
+ end
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/post_migrate/20230419012621_async_validate_fk_todos_note_id_convert_to_bigint_for_gitlab_com.rb b/db/post_migrate/20230419012621_async_validate_fk_todos_note_id_convert_to_bigint_for_gitlab_com.rb
new file mode 100644
index 00000000000..f7bef55ba01
--- /dev/null
+++ b/db/post_migrate/20230419012621_async_validate_fk_todos_note_id_convert_to_bigint_for_gitlab_com.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class AsyncValidateFkTodosNoteIdConvertToBigintForGitlabCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ TABLE_NAME = :todos
+ COLUMN = :note_id_convert_to_bigint
+ FK_NAME = :fk_todos_note_id_convert_to_bigint
+
+ def up
+ return unless should_run?
+
+ prepare_async_foreign_key_validation TABLE_NAME, COLUMN, name: FK_NAME
+ end
+
+ def down
+ return unless should_run?
+
+ unprepare_async_foreign_key_validation TABLE_NAME, COLUMN, name: FK_NAME
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end