summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20200128133510_cleanup_empty_commit_user_mentions.rb28
-rw-r--r--db/post_migrate/20200128134110_migrate_commit_notes_mentions_to_db.rb37
-rw-r--r--db/post_migrate/20200219183456_remove_issue_state_indexes.rb40
-rw-r--r--db/post_migrate/20200219184219_remove_merge_request_state_indexes.rb39
-rw-r--r--db/post_migrate/20200219193058_remove_state_from_issues.rb30
-rw-r--r--db/post_migrate/20200219193117_remove_state_from_merge_requests.rb30
-rw-r--r--db/post_migrate/20200310135818_remove_temporary_promoted_notes_index.rb22
-rw-r--r--db/schema.rb12
8 files changed, 226 insertions, 12 deletions
diff --git a/db/post_migrate/20200128133510_cleanup_empty_commit_user_mentions.rb b/db/post_migrate/20200128133510_cleanup_empty_commit_user_mentions.rb
new file mode 100644
index 00000000000..362aa3a60f7
--- /dev/null
+++ b/db/post_migrate/20200128133510_cleanup_empty_commit_user_mentions.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class CleanupEmptyCommitUserMentions < ActiveRecord::Migration[5.2]
+ DOWNTIME = false
+ BATCH_SIZE = 10_000
+
+ class CommitUserMention < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'commit_user_mentions'
+ end
+
+ def up
+ # cleanup commit user mentions with no actual mentions,
+ # re https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24586#note_285982468
+ CommitUserMention
+ .where(mentioned_users_ids: nil)
+ .where(mentioned_groups_ids: nil)
+ .where(mentioned_projects_ids: nil)
+ .each_batch(of: BATCH_SIZE) do |batch|
+ batch.delete_all
+ end
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/post_migrate/20200128134110_migrate_commit_notes_mentions_to_db.rb b/db/post_migrate/20200128134110_migrate_commit_notes_mentions_to_db.rb
new file mode 100644
index 00000000000..5b8ed99fb7a
--- /dev/null
+++ b/db/post_migrate/20200128134110_migrate_commit_notes_mentions_to_db.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+class MigrateCommitNotesMentionsToDb < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ DOWNTIME = false
+ DELAY = 3.minutes.to_i
+ BATCH_SIZE = 1_000
+ MIGRATION = 'UserMentions::CreateResourceUserMention'
+
+ QUERY_CONDITIONS = "note LIKE '%@%'::text AND notes.noteable_type = 'Commit' AND commit_user_mentions.commit_id IS NULL"
+ JOIN = 'LEFT JOIN commit_user_mentions ON notes.id = commit_user_mentions.note_id'
+
+ class Note < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'notes'
+ end
+
+ def up
+ Note
+ .joins(JOIN)
+ .where(QUERY_CONDITIONS)
+ .each_batch(of: BATCH_SIZE) do |batch, index|
+ range = batch.pluck(Arel.sql('MIN(notes.id)'), Arel.sql('MAX(notes.id)')).first
+ migrate_in(index * DELAY, MIGRATION, ['Commit', JOIN, QUERY_CONDITIONS, true, *range])
+ end
+ end
+
+ def down
+ # no-op
+ # temporary index is to be dropped in a different migration in an upcoming release:
+ # https://gitlab.com/gitlab-org/gitlab/issues/196842
+ end
+end
diff --git a/db/post_migrate/20200219183456_remove_issue_state_indexes.rb b/db/post_migrate/20200219183456_remove_issue_state_indexes.rb
new file mode 100644
index 00000000000..cdf10b8172e
--- /dev/null
+++ b/db/post_migrate/20200219183456_remove_issue_state_indexes.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+class RemoveIssueStateIndexes < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ # issues state column is ignored since 12.6 and will be removed on a following migration
+ def up
+ remove_concurrent_index_by_name :issues, 'index_issues_on_state'
+ remove_concurrent_index_by_name :issues, 'index_issues_on_project_id_and_created_at_and_id_and_state'
+ remove_concurrent_index_by_name :issues, 'idx_issues_on_project_id_and_due_date_and_id_and_state_partial'
+ remove_concurrent_index_by_name :issues, 'index_issues_on_project_id_and_rel_position_and_state_and_id'
+ remove_concurrent_index_by_name :issues, 'index_issues_on_project_id_and_updated_at_and_id_and_state'
+ end
+
+ def down
+ add_concurrent_index :issues, :state, name: 'index_issues_on_state'
+
+ add_concurrent_index :issues,
+ [:project_id, :created_at, :id, :state],
+ name: 'index_issues_on_project_id_and_created_at_and_id_and_state'
+
+ add_concurrent_index :issues,
+ [:project_id, :due_date, :id, :state],
+ where: 'due_date IS NOT NULL',
+ name: 'idx_issues_on_project_id_and_due_date_and_id_and_state_partial'
+
+ add_concurrent_index :issues,
+ [:project_id, :relative_position, :state, :id],
+ order: { id: :desc },
+ name: 'index_issues_on_project_id_and_rel_position_and_state_and_id'
+
+ add_concurrent_index :issues,
+ [:project_id, :updated_at, :id, :state],
+ name: 'index_issues_on_project_id_and_updated_at_and_id_and_state'
+ end
+end
diff --git a/db/post_migrate/20200219184219_remove_merge_request_state_indexes.rb b/db/post_migrate/20200219184219_remove_merge_request_state_indexes.rb
new file mode 100644
index 00000000000..deb95acc1cf
--- /dev/null
+++ b/db/post_migrate/20200219184219_remove_merge_request_state_indexes.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+class RemoveMergeRequestStateIndexes < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ # merge_requests state column is ignored since 12.6 and will be removed on a following migration
+ def up
+ remove_concurrent_index_by_name :merge_requests, 'index_merge_requests_on_id_and_merge_jid'
+ remove_concurrent_index_by_name :merge_requests, 'index_merge_requests_on_source_project_and_branch_state_opened'
+ remove_concurrent_index_by_name :merge_requests, 'index_merge_requests_on_state_and_merge_status'
+ remove_concurrent_index_by_name :merge_requests, 'index_merge_requests_on_target_project_id_and_iid_opened'
+ end
+
+ def down
+ add_concurrent_index :merge_requests,
+ [:id, :merge_jid],
+ where: "merge_jid IS NOT NULL and state = 'locked'",
+ name: 'index_merge_requests_on_id_and_merge_jid'
+
+ add_concurrent_index :merge_requests,
+ [:source_project_id, :source_branch],
+ where: "state = 'opened'",
+ name: 'index_merge_requests_on_source_project_and_branch_state_opened'
+
+ add_concurrent_index :merge_requests,
+ [:state, :merge_status],
+ where: "state = 'opened' AND merge_status = 'can_be_merged'",
+ name: 'index_merge_requests_on_state_and_merge_status'
+
+ add_concurrent_index :merge_requests,
+ [:target_project_id, :iid],
+ where: "state = 'opened'",
+ name: 'index_merge_requests_on_target_project_id_and_iid_opened'
+ end
+end
diff --git a/db/post_migrate/20200219193058_remove_state_from_issues.rb b/db/post_migrate/20200219193058_remove_state_from_issues.rb
new file mode 100644
index 00000000000..ac27a9a9b69
--- /dev/null
+++ b/db/post_migrate/20200219193058_remove_state_from_issues.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class RemoveStateFromIssues < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ return unless issue_state_column_exists?
+
+ # Ignored in 12.6 - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/19574
+ with_lock_retries do
+ remove_column :issues, :state, :string
+ end
+ end
+
+ def down
+ return if issue_state_column_exists?
+
+ with_lock_retries do
+ add_column :issues, :state, :string # rubocop:disable Migration/AddLimitToStringColumns
+ end
+ end
+
+ private
+
+ def issue_state_column_exists?
+ column_exists?(:issues, :state)
+ end
+end
diff --git a/db/post_migrate/20200219193117_remove_state_from_merge_requests.rb b/db/post_migrate/20200219193117_remove_state_from_merge_requests.rb
new file mode 100644
index 00000000000..c99a732f37b
--- /dev/null
+++ b/db/post_migrate/20200219193117_remove_state_from_merge_requests.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class RemoveStateFromMergeRequests < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ return unless merge_requests_state_column_exists?
+
+ # Ignored in 12.6 - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/19574
+ with_lock_retries do
+ remove_column :merge_requests, :state, :string
+ end
+ end
+
+ def down
+ return if merge_requests_state_column_exists?
+
+ with_lock_retries do
+ add_column :merge_requests, :state, :string # rubocop:disable Migration/AddLimitToStringColumns
+ end
+ end
+
+ private
+
+ def merge_requests_state_column_exists?
+ column_exists?(:merge_requests, :state)
+ end
+end
diff --git a/db/post_migrate/20200310135818_remove_temporary_promoted_notes_index.rb b/db/post_migrate/20200310135818_remove_temporary_promoted_notes_index.rb
new file mode 100644
index 00000000000..0b9bbf1e17b
--- /dev/null
+++ b/db/post_migrate/20200310135818_remove_temporary_promoted_notes_index.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+# Removes temporary index to fix orphan promoted issues.
+# For more information check: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/23916
+class RemoveTemporaryPromotedNotesIndex < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name :notes, 'tmp_idx_on_promoted_notes'
+ end
+
+ def down
+ add_concurrent_index :notes,
+ :note,
+ where: "noteable_type = 'Issue' AND system IS TRUE AND note LIKE 'promoted to epic%'",
+ name: 'tmp_idx_on_promoted_notes'
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 8aad65e9b35..06f2011c568 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -2184,7 +2184,6 @@ ActiveRecord::Schema.define(version: 2020_03_11_165635) do
t.datetime "updated_at"
t.text "description"
t.integer "milestone_id"
- t.string "state"
t.integer "iid"
t.integer "updated_by_id"
t.integer "weight"
@@ -2216,18 +2215,13 @@ ActiveRecord::Schema.define(version: 2020_03_11_165635) do
t.index ["lock_version"], name: "index_issues_on_lock_version", where: "(lock_version IS NULL)"
t.index ["milestone_id"], name: "index_issues_on_milestone_id"
t.index ["moved_to_id"], name: "index_issues_on_moved_to_id", where: "(moved_to_id IS NOT NULL)"
- t.index ["project_id", "created_at", "id", "state"], name: "index_issues_on_project_id_and_created_at_and_id_and_state"
t.index ["project_id", "created_at", "id", "state_id"], name: "idx_issues_on_project_id_and_created_at_and_id_and_state_id"
- t.index ["project_id", "due_date", "id", "state"], name: "idx_issues_on_project_id_and_due_date_and_id_and_state_partial", where: "(due_date IS NOT NULL)"
t.index ["project_id", "due_date", "id", "state_id"], name: "idx_issues_on_project_id_and_due_date_and_id_and_state_id", where: "(due_date IS NOT NULL)"
t.index ["project_id", "iid"], name: "index_issues_on_project_id_and_iid", unique: true
- t.index ["project_id", "relative_position", "state", "id"], name: "index_issues_on_project_id_and_rel_position_and_state_and_id", order: { id: :desc }
t.index ["project_id", "relative_position", "state_id", "id"], name: "idx_issues_on_project_id_and_rel_position_and_state_id_and_id", order: { id: :desc }
- t.index ["project_id", "updated_at", "id", "state"], name: "index_issues_on_project_id_and_updated_at_and_id_and_state"
t.index ["project_id", "updated_at", "id", "state_id"], name: "idx_issues_on_project_id_and_updated_at_and_id_and_state_id"
t.index ["promoted_to_epic_id"], name: "index_issues_on_promoted_to_epic_id", where: "(promoted_to_epic_id IS NOT NULL)"
t.index ["relative_position"], name: "index_issues_on_relative_position"
- t.index ["state"], name: "index_issues_on_state"
t.index ["state_id"], name: "idx_issues_on_state_id"
t.index ["title"], name: "index_issues_on_title_trigram", opclass: :gin_trgm_ops, using: :gin
t.index ["updated_at"], name: "index_issues_on_updated_at"
@@ -2597,7 +2591,6 @@ ActiveRecord::Schema.define(version: 2020_03_11_165635) do
t.datetime "created_at"
t.datetime "updated_at"
t.integer "milestone_id"
- t.string "state", default: "opened", null: false
t.string "merge_status", default: "unchecked", null: false
t.integer "target_project_id", null: false
t.integer "iid"
@@ -2633,7 +2626,6 @@ ActiveRecord::Schema.define(version: 2020_03_11_165635) do
t.index ["description"], name: "index_merge_requests_on_description_trigram", opclass: :gin_trgm_ops, using: :gin
t.index ["head_pipeline_id"], name: "index_merge_requests_on_head_pipeline_id"
t.index ["id", "merge_jid"], name: "idx_merge_requests_on_id_and_merge_jid", where: "((merge_jid IS NOT NULL) AND (state_id = 4))"
- t.index ["id", "merge_jid"], name: "index_merge_requests_on_id_and_merge_jid", where: "((merge_jid IS NOT NULL) AND ((state)::text = 'locked'::text))"
t.index ["id"], name: "merge_request_mentions_temp_index", where: "((description ~~ '%@%'::text) OR ((title)::text ~~ '%@%'::text))"
t.index ["latest_merge_request_diff_id"], name: "index_merge_requests_on_latest_merge_request_diff_id"
t.index ["lock_version"], name: "index_merge_requests_on_lock_version", where: "(lock_version IS NULL)"
@@ -2641,15 +2633,12 @@ ActiveRecord::Schema.define(version: 2020_03_11_165635) do
t.index ["milestone_id"], name: "index_merge_requests_on_milestone_id"
t.index ["source_branch"], name: "index_merge_requests_on_source_branch"
t.index ["source_project_id", "source_branch"], name: "idx_merge_requests_on_source_project_and_branch_state_opened", where: "(state_id = 1)"
- t.index ["source_project_id", "source_branch"], name: "index_merge_requests_on_source_project_and_branch_state_opened", where: "((state)::text = 'opened'::text)"
t.index ["source_project_id", "source_branch"], name: "index_merge_requests_on_source_project_id_and_source_branch"
- t.index ["state", "merge_status"], name: "index_merge_requests_on_state_and_merge_status", where: "(((state)::text = 'opened'::text) AND ((merge_status)::text = 'can_be_merged'::text))"
t.index ["state_id", "merge_status"], name: "idx_merge_requests_on_state_id_and_merge_status", where: "((state_id = 1) AND ((merge_status)::text = 'can_be_merged'::text))"
t.index ["target_branch"], name: "index_merge_requests_on_target_branch"
t.index ["target_project_id", "created_at"], name: "index_merge_requests_target_project_id_created_at"
t.index ["target_project_id", "iid"], name: "idx_merge_requests_on_target_project_id_and_iid_opened", where: "(state_id = 1)"
t.index ["target_project_id", "iid"], name: "index_merge_requests_on_target_project_id_and_iid", unique: true
- t.index ["target_project_id", "iid"], name: "index_merge_requests_on_target_project_id_and_iid_opened", where: "((state)::text = 'opened'::text)"
t.index ["target_project_id", "merge_commit_sha", "id"], name: "index_merge_requests_on_tp_id_and_merge_commit_sha_and_id"
t.index ["target_project_id", "target_branch"], name: "index_merge_requests_on_target_project_id_and_target_branch", where: "((state_id = 1) AND (merge_when_pipeline_succeeds = true))"
t.index ["title"], name: "index_merge_requests_on_title"
@@ -2844,7 +2833,6 @@ ActiveRecord::Schema.define(version: 2020_03_11_165635) do
t.index ["id", "noteable_type"], name: "note_mentions_temp_index", where: "(note ~~ '%@%'::text)"
t.index ["line_code"], name: "index_notes_on_line_code"
t.index ["note"], name: "index_notes_on_note_trigram", opclass: :gin_trgm_ops, using: :gin
- t.index ["note"], name: "tmp_idx_on_promoted_notes", where: "(((noteable_type)::text = 'Issue'::text) AND (system IS TRUE) AND (note ~~ 'promoted to epic%'::text))"
t.index ["noteable_id", "noteable_type"], name: "index_notes_on_noteable_id_and_noteable_type"
t.index ["project_id", "id"], name: "index_notes_on_project_id_and_id_and_system_false", where: "(NOT system)"
t.index ["project_id", "noteable_type"], name: "index_notes_on_project_id_and_noteable_type"