debian-mirror-gitlab/app/models/deployment_merge_request.rb

35 lines
998 B
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
class DeploymentMergeRequest < ApplicationRecord
2021-03-11 19:13:27 +05:30
extend SuppressCompositePrimaryKeyWarning
2019-12-26 22:10:19 +05:30
belongs_to :deployment, optional: false
belongs_to :merge_request, optional: false
2021-01-03 14:25:43 +05:30
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)
where('deployments.id = ?', id)
end
def self.deployed_to(name)
2021-01-29 00:20:46 +05:30
# 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-01-03 14:25:43 +05:30
where('environments.name = ?', name)
2021-01-29 00:20:46 +05:30
.where('environments.project_id = merge_requests.target_project_id')
2021-01-03 14:25:43 +05:30
end
def self.deployed_after(time)
where('deployments.finished_at > ?', time)
end
def self.deployed_before(time)
where('deployments.finished_at < ?', time)
end
2019-12-26 22:10:19 +05:30
end