Commit 17525190 authored by Andreas Brandl's avatar Andreas Brandl

Merge branch '32229-followup-pa-merged-at-index' into 'master'

Replace temporary productivity analytics index

Closes #32229

See merge request gitlab-org/gitlab!17957
parents 29cabf06 a015e922
# frozen_string_literal: true
class ReplaceIndexOnMetricsMergedAt < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :merge_request_metrics, :merged_at
remove_concurrent_index :merge_request_metrics, [:merged_at, :id]
end
def down
add_concurrent_index :merge_request_metrics, [:merged_at, :id]
remove_concurrent_index :merge_request_metrics, :merged_at
end
end
......@@ -6,7 +6,7 @@ class ScheduleProductivityAnalyticsBackfill < ActiveRecord::Migration[5.2]
DOWNTIME = false
def up
# no-op since the scheduling times out on GitLab.com
# no-op since the migration was removed
end
def down
......
......@@ -2290,7 +2290,7 @@ ActiveRecord::Schema.define(version: 2019_11_05_094625) do
t.index ["latest_closed_by_id"], name: "index_merge_request_metrics_on_latest_closed_by_id"
t.index ["merge_request_id", "merged_at"], name: "index_merge_request_metrics_on_merge_request_id_and_merged_at", where: "(merged_at IS NOT NULL)"
t.index ["merge_request_id"], name: "index_merge_request_metrics"
t.index ["merged_at", "id"], name: "index_merge_request_metrics_on_merged_at_and_id"
t.index ["merged_at"], name: "index_merge_request_metrics_on_merged_at"
t.index ["merged_by_id"], name: "index_merge_request_metrics_on_merged_by_id"
t.index ["pipeline_id"], name: "index_merge_request_metrics_on_pipeline_id"
end
......
# frozen_string_literal: true
module Gitlab
module BackgroundMigration
class RecalculateProductivityAnalytics
def perform(_start_id, _end_id)
# Do nothing. Migration is removed.
# By keeping the class for a while we allow workers to work off for those environments
# which have scheduled the migration.
# Will be removed completely in https://gitlab.com/gitlab-org/gitlab/merge_requests/17957
end
end
end
end
# frozen_string_literal: true
module MigrationHelpers
module RecalculateProductivityAnalyticsHelpers
def create_populated_mr(user, project, attributes: {}, metrics: {})
base = {
author_id: user.id,
source_project_id: project.id,
target_project_id: project.id,
source_branch: 'master',
target_branch: 'feature'
}
mr = table(:merge_requests).create!(base.merge(attributes))
table(:merge_request_metrics).create!(metrics.merge(merge_request_id: mr.id))
create_mr_activity(mr)
create_notes(mr)
mr
end
def create_notes(mr)
# 4 notes per MR
table(:notes).create!(note: 'sample note', noteable_type: 'MergeRequest', noteable_id: mr.id, author_id: user.id, created_at: 4.weeks.ago + 1.day)
table(:notes).create!(note: 'sample note 2', noteable_type: 'MergeRequest', noteable_id: mr.id, author_id: user.id, created_at: 4.weeks.ago + 2.days)
table(:notes).create!(note: 'system note', noteable_type: 'MergeRequest', noteable_id: mr.id, created_at: 4.weeks.ago + 3.days)
table(:notes).create!(note: 'bot note', noteable_type: 'MergeRequest', noteable_id: mr.id, author_id: bot.id, created_at: 4.weeks.ago + 2.days)
end
def create_mr_activity(mr)
diff = table(:merge_request_diffs).create!(merge_request_id: mr.id, commits_count: 2)
# 2 commits per MR
table(:merge_request_diff_commits).create!(sha: '456', merge_request_diff_id: diff.id, authored_date: 2.weeks.ago, committed_date: 1.week.ago, relative_order: 0)
table(:merge_request_diff_commits).create!(sha: '123', merge_request_diff_id: diff.id, authored_date: 4.weeks.ago, committed_date: 3.weeks.ago, relative_order: 1)
# 2 diff files per MR
base_diff_files_attributes = {
merge_request_diff_id: diff.id,
new_file: true,
renamed_file: false,
deleted_file: false,
too_large: false,
a_mode: '0',
b_mode: '160000',
diff: "@@ -1,6 +1,6 @@\n class Commit\n constructor: ->\n $('.files .diff-file').each ->\n- new CommitFile(this)\n+ new CommitFile(@)\n \n-@Commit = Commit\n+@Commit = Commit\n\\ No newline at end of file\n",
binary: false
}
table(:merge_request_diff_files).create!(
base_diff_files_attributes.merge(relative_order: 1, new_path: 'test_file', old_path: 'test_file')
)
table(:merge_request_diff_files).create!(
base_diff_files_attributes.merge(relative_order: 2, new_path: 'test_file_2', old_path: 'test_file_2')
)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment