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
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-13 06:08:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-13 06:08:51 +0300
commitb9abe8515111c39c65321258d760aaf4773cb55f (patch)
treea58816df2053183f855389c37945ed17578a76aa /db
parentfa1b90364dc73f27dc78b9d27114e4a197f2cfcb (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20230403041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com.rb81
-rw-r--r--db/post_migrate/20230413041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com_2.rb93
-rw-r--r--db/schema_migrations/202304130419171
3 files changed, 97 insertions, 78 deletions
diff --git a/db/post_migrate/20230403041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com.rb b/db/post_migrate/20230403041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com.rb
index e2a08276343..fb941e1cb51 100644
--- a/db/post_migrate/20230403041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com.rb
+++ b/db/post_migrate/20230403041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com.rb
@@ -1,83 +1,8 @@
# frozen_string_literal: true
class SwapIssueUserMentionsNoteIdToBigintForGitlabDotCom < Gitlab::Database::Migration[2.1]
- include Gitlab::Database::MigrationHelpers::ConvertToBigint
+ # No-op, moved to db/post_migrate/20230413041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com_2.rb
+ def up; end
- disable_ddl_transaction!
-
- TABLE_NAME = 'issue_user_mentions'
-
- def up
- return unless should_run?
-
- swap
- end
-
- def down
- return unless should_run?
-
- swap
-
- add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
- name: 'index_issue_user_mentions_on_note_id_convert_to_bigint',
- where: 'note_id_convert_to_bigint IS NOT NULL'
-
- add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
- name: 'fk_issue_user_mentions_note_id_convert_to_bigint',
- on_delete: :cascade,
- validate: false
- end
-
- def swap
- # This will replace the existing index_issue_user_mentions_on_note_id
- add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
- name: 'index_issue_user_mentions_on_note_id_convert_to_bigint',
- where: 'note_id_convert_to_bigint IS NOT NULL'
-
- # This will replace the existing issue_user_mentions_on_issue_id_and_note_id_index
- add_concurrent_index TABLE_NAME, [:issue_id, :note_id_convert_to_bigint], unique: true,
- name: 'tmp_issue_user_mentions_on_issue_id_and_note_id_index'
-
- # This will replace the existing issue_user_mentions_on_issue_id_index
- add_concurrent_index TABLE_NAME, :issue_id, unique: true,
- name: 'tmp_issue_user_mentions_on_issue_id_index',
- where: 'note_id_convert_to_bigint IS NULL'
-
- # This will replace the existing fk_rails_3861d9fefa
- add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
- name: 'fk_issue_user_mentions_note_id_convert_to_bigint',
- on_delete: :cascade
-
- with_lock_retries(raise_on_exhaustion: true) do
- execute "LOCK TABLE notes, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
-
- execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id TO note_id_tmp"
- execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_convert_to_bigint TO note_id"
- execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_tmp TO note_id_convert_to_bigint"
-
- function_name = Gitlab::Database::UnidirectionalCopyTrigger
- .on_table(TABLE_NAME, connection: connection)
- .name(:note_id, :note_id_convert_to_bigint)
- execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
-
- execute 'DROP INDEX IF EXISTS index_issue_user_mentions_on_note_id'
- rename_index TABLE_NAME, 'index_issue_user_mentions_on_note_id_convert_to_bigint',
- 'index_issue_user_mentions_on_note_id'
-
- execute 'DROP INDEX IF EXISTS issue_user_mentions_on_issue_id_and_note_id_index'
- rename_index TABLE_NAME, 'tmp_issue_user_mentions_on_issue_id_and_note_id_index',
- 'issue_user_mentions_on_issue_id_and_note_id_index'
-
- execute 'DROP INDEX IF EXISTS issue_user_mentions_on_issue_id_index'
- rename_index TABLE_NAME, 'tmp_issue_user_mentions_on_issue_id_index',
- 'issue_user_mentions_on_issue_id_index'
-
- execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_rails_3861d9fefa"
- rename_constraint(TABLE_NAME, 'fk_issue_user_mentions_note_id_convert_to_bigint', 'fk_rails_3861d9fefa')
- end
- end
-
- def should_run?
- com_or_dev_or_test_but_not_jh?
- end
+ def down; end
end
diff --git a/db/post_migrate/20230413041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com_2.rb b/db/post_migrate/20230413041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com_2.rb
new file mode 100644
index 00000000000..cb29b47a64d
--- /dev/null
+++ b/db/post_migrate/20230413041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com_2.rb
@@ -0,0 +1,93 @@
+# frozen_string_literal: true
+
+class SwapIssueUserMentionsNoteIdToBigintForGitlabDotCom2 < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = 'issue_user_mentions'
+
+ def up
+ return unless should_run?
+ return if columns_alredy_swapped?
+
+ swap
+ end
+
+ def down
+ return unless should_run?
+ return unless columns_alredy_swapped?
+
+ swap
+
+ add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
+ name: 'index_issue_user_mentions_on_note_id_convert_to_bigint',
+ where: 'note_id_convert_to_bigint IS NOT NULL'
+
+ add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
+ name: 'fk_issue_user_mentions_note_id_convert_to_bigint',
+ on_delete: :cascade,
+ validate: false
+ end
+
+ def swap
+ # This will replace the existing index_issue_user_mentions_on_note_id
+ add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true,
+ name: 'index_issue_user_mentions_on_note_id_convert_to_bigint',
+ where: 'note_id_convert_to_bigint IS NOT NULL'
+
+ # This will replace the existing issue_user_mentions_on_issue_id_and_note_id_index
+ add_concurrent_index TABLE_NAME, [:issue_id, :note_id_convert_to_bigint], unique: true,
+ name: 'tmp_issue_user_mentions_on_issue_id_and_note_id_index'
+
+ # This will replace the existing issue_user_mentions_on_issue_id_index
+ add_concurrent_index TABLE_NAME, :issue_id, unique: true,
+ name: 'tmp_issue_user_mentions_on_issue_id_index',
+ where: 'note_id_convert_to_bigint IS NULL'
+
+ # This will replace the existing fk_rails_3861d9fefa
+ add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint,
+ name: 'fk_issue_user_mentions_note_id_convert_to_bigint',
+ on_delete: :cascade
+
+ with_lock_retries(raise_on_exhaustion: true) do
+ execute "LOCK TABLE notes, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
+
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id TO note_id_tmp"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_convert_to_bigint TO note_id"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_tmp TO note_id_convert_to_bigint"
+
+ function_name = Gitlab::Database::UnidirectionalCopyTrigger
+ .on_table(TABLE_NAME, connection: connection)
+ .name(:note_id, :note_id_convert_to_bigint)
+ execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
+
+ execute 'DROP INDEX IF EXISTS index_issue_user_mentions_on_note_id'
+ rename_index TABLE_NAME, 'index_issue_user_mentions_on_note_id_convert_to_bigint',
+ 'index_issue_user_mentions_on_note_id'
+
+ execute 'DROP INDEX IF EXISTS issue_user_mentions_on_issue_id_and_note_id_index'
+ rename_index TABLE_NAME, 'tmp_issue_user_mentions_on_issue_id_and_note_id_index',
+ 'issue_user_mentions_on_issue_id_and_note_id_index'
+
+ execute 'DROP INDEX IF EXISTS issue_user_mentions_on_issue_id_index'
+ rename_index TABLE_NAME, 'tmp_issue_user_mentions_on_issue_id_index',
+ 'issue_user_mentions_on_issue_id_index'
+
+ execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_rails_3861d9fefa"
+ rename_constraint(TABLE_NAME, 'fk_issue_user_mentions_note_id_convert_to_bigint', 'fk_rails_3861d9fefa')
+ end
+ end
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+
+ def columns_alredy_swapped?
+ table_columns = columns(TABLE_NAME)
+ note_id = table_columns.find { |c| c.name == 'note_id' }
+ note_id_convert_to_bigint = table_columns.find { |c| c.name == 'note_id_convert_to_bigint' }
+
+ note_id_convert_to_bigint.sql_type == 'integer' && note_id.sql_type == 'bigint'
+ end
+end
diff --git a/db/schema_migrations/20230413041917 b/db/schema_migrations/20230413041917
new file mode 100644
index 00000000000..f4c1f05a565
--- /dev/null
+++ b/db/schema_migrations/20230413041917
@@ -0,0 +1 @@
+c359118e94c992bd19d8f0bd10f702bc117c944663a1f84f3d678bada242c09d \ No newline at end of file