Commit 52e2729b authored by James Lopez's avatar James Lopez

add pipeline id to merge request metrics table. Also, updated the pipeline...

add pipeline id to merge request metrics table. Also, updated the pipeline worker to populate this field.
parent 1a4ff5d7
...@@ -232,7 +232,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -232,7 +232,7 @@ class MergeRequest < ActiveRecord::Base
end end
def diff_head_commit def diff_head_commit
if persisted? if persisted?diff_head_commit
merge_request_diff.head_commit merge_request_diff.head_commit
else else
source_branch_head source_branch_head
......
class MergeRequest::Metrics < ActiveRecord::Base class MergeRequest::Metrics < ActiveRecord::Base
belongs_to :merge_request belongs_to :merge_request
belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :ci_commit_id
def record! def record!
if merge_request.merged? && self.merged_at.blank? if merge_request.merged? && self.merged_at.blank?
......
...@@ -12,11 +12,11 @@ class PipelineMetricsWorker ...@@ -12,11 +12,11 @@ class PipelineMetricsWorker
private private
def update_metrics_for_active_pipeline(pipeline) def update_metrics_for_active_pipeline(pipeline)
metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: nil) metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: nil, ci_commit_id: pipeline.id)
end end
def update_metrics_for_succeeded_pipeline(pipeline) def update_metrics_for_succeeded_pipeline(pipeline)
metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at) metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at, ci_commit_id: pipeline.id)
end end
def metrics(pipeline) def metrics(pipeline)
......
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddPipelineIdToMergeRequestMetrics < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = true
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
DOWNTIME_REASON = 'Adding a foreign key'
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
# existing transaction. When using "add_concurrent_index" make sure that this
# method is the _only_ method called in the migration, any other changes
# should go in a separate migration. This ensures that upon failure _only_ the
# index creation fails and can be retried or reverted easily.
#
# To disable transactions uncomment the following line and remove these
# comments:
# disable_ddl_transaction!
def change
add_reference :merge_request_metrics, :ci_commit, index: true, foreign_key: { on_delete: :cascade }
end
end
...@@ -634,8 +634,10 @@ ActiveRecord::Schema.define(version: 20161109150329) do ...@@ -634,8 +634,10 @@ ActiveRecord::Schema.define(version: 20161109150329) do
t.datetime "merged_at" t.datetime "merged_at"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "ci_commit_id"
end end
add_index "merge_request_metrics", ["ci_commit_id"], name: "index_merge_request_metrics_on_ci_commit_id", using: :btree
add_index "merge_request_metrics", ["first_deployed_to_production_at"], name: "index_merge_request_metrics_on_first_deployed_to_production_at", using: :btree add_index "merge_request_metrics", ["first_deployed_to_production_at"], name: "index_merge_request_metrics_on_first_deployed_to_production_at", using: :btree
add_index "merge_request_metrics", ["merge_request_id"], name: "index_merge_request_metrics", using: :btree add_index "merge_request_metrics", ["merge_request_id"], name: "index_merge_request_metrics", using: :btree
...@@ -1244,6 +1246,7 @@ ActiveRecord::Schema.define(version: 20161109150329) do ...@@ -1244,6 +1246,7 @@ ActiveRecord::Schema.define(version: 20161109150329) do
add_foreign_key "labels", "namespaces", column: "group_id", on_delete: :cascade add_foreign_key "labels", "namespaces", column: "group_id", on_delete: :cascade
add_foreign_key "lists", "boards" add_foreign_key "lists", "boards"
add_foreign_key "lists", "labels" add_foreign_key "lists", "labels"
add_foreign_key "merge_request_metrics", "ci_commits", on_delete: :cascade
add_foreign_key "merge_request_metrics", "merge_requests", on_delete: :cascade add_foreign_key "merge_request_metrics", "merge_requests", on_delete: :cascade
add_foreign_key "merge_requests_closing_issues", "issues", on_delete: :cascade add_foreign_key "merge_requests_closing_issues", "issues", on_delete: :cascade
add_foreign_key "merge_requests_closing_issues", "merge_requests", on_delete: :cascade add_foreign_key "merge_requests_closing_issues", "merge_requests", on_delete: :cascade
......
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