diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /app/models/environment.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r-- | app/models/environment.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index f1edfb3a34b..7d99f10822d 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -98,6 +98,27 @@ class Environment < ApplicationRecord scope :auto_stoppable, -> (limit) { available.where('auto_stop_at < ?', Time.zone.now).limit(limit) } scope :auto_deletable, -> (limit) { stopped.where('auto_delete_at < ?', Time.zone.now).limit(limit) } + scope :deployed_and_updated_before, -> (project_id, before) do + # this query joins deployments and filters out any environment that has recent deployments + joins = %{ + LEFT JOIN "deployments" on "deployments".environment_id = "environments".id + AND "deployments".project_id = #{project_id} + AND "deployments".updated_at >= #{connection.quote(before)} + } + Environment.joins(joins) + .where(project_id: project_id, updated_at: ...before) + .group('id', 'deployments.id') + .having('deployments.id IS NULL') + end + scope :without_protected, -> (project) {} # no-op when not in EE mode + + scope :without_names, -> (names) do + where.not(name: names) + end + scope :without_tiers, -> (tiers) do + where.not(tier: tiers) + end + ## # Search environments which have names like the given query. # Do not set a large limit unless you've confirmed that it works on gitlab.com scale. |