Skip to content
Snippets Groups Projects
Commit 85dcd0a9 authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Fix environments query for pipeline

This commit fixes the database query to fetch
related environments of a pipeline.

The feature is still behind a feature flag.
parent 09a4bb5b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -958,7 +958,7 @@ def environments_in_self_and_descendants
.limit(100)
.pluck(:expanded_environment_name)
 
Environment.where(project: project, name: expanded_environment_names).with_deployments
Environment.where(project: project, name: expanded_environment_names).with_deployment(sha)
else
environment_ids = self_and_descendants.joins(:deployments).select(:'deployments.environment_id')
 
Loading
Loading
Loading
Loading
@@ -89,7 +89,6 @@ class Environment < ApplicationRecord
 
scope :for_project, -> (project) { where(project_id: project) }
scope :for_tier, -> (tier) { where(tier: tier).where.not(tier: nil) }
scope :with_deployments, -> { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id')) }
scope :with_deployment, -> (sha) { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id').where(sha: sha)) }
scope :unfoldered, -> { where(environment_type: nil) }
scope :with_rank, -> do
Loading
Loading
Loading
Loading
@@ -3205,11 +3205,21 @@ def create_pipeline(status, ref, sha)
 
context 'when pipeline is not child nor parent' do
let_it_be(:pipeline) { create(:ci_pipeline, :created) }
let_it_be(:build) { create(:ci_build, :with_deployment, :deploy_to_production, pipeline: pipeline) }
let_it_be(:build, refind: true) { create(:ci_build, :with_deployment, :deploy_to_production, pipeline: pipeline) }
 
it 'returns just the pipeline environment' do
expect(subject).to contain_exactly(build.deployment.environment)
end
context 'when deployment SHA is not matched' do
before do
build.deployment.update!(sha: 'old-sha')
end
it 'does not return environments' do
expect(subject).to be_empty
end
end
end
 
context 'when an associated environment does not have deployments' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment