2019-11-06 19:06:18 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class DeploymentMergeRequest < ApplicationRecord
|
2021-01-27 07:09:01 -05:00
|
|
|
extend SuppressCompositePrimaryKeyWarning
|
|
|
|
|
2019-11-06 19:06:18 -05:00
|
|
|
belongs_to :deployment, optional: false
|
|
|
|
belongs_to :merge_request, optional: false
|
2020-10-19 02:09:08 -04:00
|
|
|
|
|
|
|
def self.join_deployments_for_merge_requests
|
|
|
|
joins(deployment: :environment)
|
|
|
|
.where('deployment_merge_requests.merge_request_id = merge_requests.id')
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.by_deployment_id(id)
|
2021-04-26 08:09:44 -04:00
|
|
|
where(deployments: { id: id })
|
2020-10-19 02:09:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.deployed_to(name)
|
2020-10-29 14:09:11 -04:00
|
|
|
# We filter by project ID again so the query uses the index on
|
|
|
|
# (project_id, name), instead of using the index on
|
|
|
|
# (name varchar_pattern_ops). This results in better performance on
|
|
|
|
# GitLab.com.
|
2021-04-26 08:09:44 -04:00
|
|
|
where(environments: { name: name })
|
2020-10-29 14:09:11 -04:00
|
|
|
.where('environments.project_id = merge_requests.target_project_id')
|
2020-10-19 02:09:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.deployed_after(time)
|
|
|
|
where('deployments.finished_at > ?', time)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.deployed_before(time)
|
|
|
|
where('deployments.finished_at < ?', time)
|
|
|
|
end
|
2019-11-06 19:06:18 -05:00
|
|
|
end
|