summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20230502102832_schedule_index_to_members_on_source_and_type_and_access_level.rb13
-rw-r--r--db/post_migrate/20230502120021_schedule_index_to_project_authorizations_on_project_user_access_level.rb15
-rw-r--r--db/post_migrate/20230504010535_ensure_notes_bigint_backfill_is_finished_for_gitlab_dot_com.rb29
-rw-r--r--db/post_migrate/20230508034422_notes_bigint_create_indexes_async_for_gitlab_dot_com.rb64
4 files changed, 121 insertions, 0 deletions
diff --git a/db/post_migrate/20230502102832_schedule_index_to_members_on_source_and_type_and_access_level.rb b/db/post_migrate/20230502102832_schedule_index_to_members_on_source_and_type_and_access_level.rb
new file mode 100644
index 00000000000..ce3f0fb8c76
--- /dev/null
+++ b/db/post_migrate/20230502102832_schedule_index_to_members_on_source_and_type_and_access_level.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ScheduleIndexToMembersOnSourceAndTypeAndAccessLevel < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_members_on_source_and_type_and_access_level'
+
+ def up
+ prepare_async_index :members, %i[source_id source_type type access_level], name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :members, %i[source_id source_type type access_level], name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230502120021_schedule_index_to_project_authorizations_on_project_user_access_level.rb b/db/post_migrate/20230502120021_schedule_index_to_project_authorizations_on_project_user_access_level.rb
new file mode 100644
index 00000000000..06ff40cddde
--- /dev/null
+++ b/db/post_migrate/20230502120021_schedule_index_to_project_authorizations_on_project_user_access_level.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class ScheduleIndexToProjectAuthorizationsOnProjectUserAccessLevel < Gitlab::Database::Migration[2.1]
+ INDEX_NAME = 'index_project_authorizations_on_project_user_access_level'
+
+ disable_ddl_transaction!
+
+ def up
+ prepare_async_index :project_authorizations, %i[project_id user_id access_level], unique: true, name: INDEX_NAME
+ end
+
+ def down
+ unprepare_async_index :project_authorizations, %i[project_id user_id access_level], name: INDEX_NAME
+ end
+end
diff --git a/db/post_migrate/20230504010535_ensure_notes_bigint_backfill_is_finished_for_gitlab_dot_com.rb b/db/post_migrate/20230504010535_ensure_notes_bigint_backfill_is_finished_for_gitlab_dot_com.rb
new file mode 100644
index 00000000000..b9d3dc55661
--- /dev/null
+++ b/db/post_migrate/20230504010535_ensure_notes_bigint_backfill_is_finished_for_gitlab_dot_com.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class EnsureNotesBigintBackfillIsFinishedForGitlabDotCom < 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: 'notes',
+ column_name: 'id',
+ job_arguments: [['id'], ['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/20230508034422_notes_bigint_create_indexes_async_for_gitlab_dot_com.rb b/db/post_migrate/20230508034422_notes_bigint_create_indexes_async_for_gitlab_dot_com.rb
new file mode 100644
index 00000000000..b8e8c995713
--- /dev/null
+++ b/db/post_migrate/20230508034422_notes_bigint_create_indexes_async_for_gitlab_dot_com.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+class NotesBigintCreateIndexesAsyncForGitlabDotCom < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ TABLE_NAME = 'notes'
+ PK_INDEX_NAME = 'index_notes_on_id_convert_to_bigint'
+
+ SECONDARY_INDEXES = [
+ {
+ name: :index_notes_on_author_id_created_at_id_convert_to_bigint,
+ columns: [:author_id, :created_at, :id_convert_to_bigint],
+ options: {}
+ },
+ {
+ name: :index_notes_on_id_convert_to_bigint_where_confidential,
+ columns: [:id_convert_to_bigint],
+ options: { where: 'confidential = true' }
+ },
+ {
+ name: :index_notes_on_id_convert_to_bigint_where_internal,
+ columns: [:id_convert_to_bigint],
+ options: { where: 'internal = true' }
+ },
+ {
+ name: :index_notes_on_project_id_id_convert_to_bigint_system_false,
+ columns: [:project_id, :id_convert_to_bigint],
+ options: { where: 'NOT system' }
+ },
+ {
+ name: :note_mentions_temp_index_convert_to_bigint,
+ columns: [:id_convert_to_bigint, :noteable_type],
+ options: { where: "note ~~ '%@%'::text" }
+ }
+ ]
+
+ # Indexes will be created synchronously in
+ # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/119705
+ def up
+ return unless should_run?
+
+ prepare_async_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: PK_INDEX_NAME
+
+ SECONDARY_INDEXES.each do |index|
+ prepare_async_index TABLE_NAME, index[:columns], **index[:options].merge(name: index[:name])
+ end
+ end
+
+ def down
+ return unless should_run?
+
+ SECONDARY_INDEXES.each do |index|
+ unprepare_async_index TABLE_NAME, index[:columns], name: index[:name]
+ end
+
+ unprepare_async_index TABLE_NAME, :id_convert_to_bigint, name: PK_INDEX_NAME
+ end
+
+ private
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end