diff options
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r-- | app/models/environment.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index cfdcb0499e6..66613869915 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -4,12 +4,15 @@ class Environment < ApplicationRecord include Gitlab::Utils::StrongMemoize include ReactiveCaching include FastDestroyAll::Helpers + include Presentable self.reactive_cache_refresh_interval = 1.minute self.reactive_cache_lifetime = 55.seconds self.reactive_cache_hard_limit = 10.megabytes self.reactive_cache_work_type = :external_dependency + PRODUCTION_ENVIRONMENT_IDENTIFIERS = %w[prod production].freeze + belongs_to :project, required: true use_fast_destroy :all_deployments @@ -67,6 +70,7 @@ class Environment < ApplicationRecord scope :order_by_last_deployed_at_desc, -> do order(Gitlab::Database.nulls_last_order("(#{max_deployment_id_sql})", 'DESC')) end + scope :order_by_name, -> { order('environments.name ASC') } scope :in_review_folder, -> { where(environment_type: "review") } scope :for_name, -> (name) { where(name: name) } @@ -86,6 +90,7 @@ class Environment < ApplicationRecord scope :with_rank, -> do select('environments.*, rank() OVER (PARTITION BY project_id ORDER BY id DESC)') end + scope :for_id, -> (id) { where(id: id) } state_machine :state, initial: :available do event :start do @@ -118,6 +123,10 @@ class Environment < ApplicationRecord pluck(:name) end + def self.pluck_unique_names + pluck('DISTINCT(environments.name)') + end + def self.find_or_create_by_name(name) find_or_create_by(name: name) end @@ -211,7 +220,7 @@ class Environment < ApplicationRecord end def update_merge_request_metrics? - folder_name == "production" + PRODUCTION_ENVIRONMENT_IDENTIFIERS.include?(folder_name.downcase) end def ref_path |