From a8e9910e43ac6b9bdf279f79ea03a6a2f1179a9b Mon Sep 17 00:00:00 2001 From: Tiger Date: Tue, 17 Jun 2025 12:27:28 +1200 Subject: [PATCH] Use auto_stop_in value from options instead of column This value is currently stored twice in the `p_ci_builds_metadata` table: serialized within `options` and in `environment_auto_stop_in`. There are no queries that benefit from the dedicated column, so it can be removed. --- app/models/commit_status.rb | 2 ++ app/models/concerns/ci/deployable.rb | 4 ++++ app/models/concerns/ci/metadatable.rb | 2 -- .../ci/deployable_shared_examples.rb | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 90876cbb4d878b..d19863f5c25806 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -9,6 +9,8 @@ class CommitStatus < Ci::ApplicationRecord include BulkInsertableAssociations include TaggableQueries + ignore_column :environment_auto_stop_in, remove_with: '18.4', remove_after: '2025-09-01' + self.table_name = :p_ci_builds self.sequence_name = :ci_builds_id_seq self.primary_key = :id diff --git a/app/models/concerns/ci/deployable.rb b/app/models/concerns/ci/deployable.rb index 0956a9eb3243ff..010a8bca95166a 100644 --- a/app/models/concerns/ci/deployable.rb +++ b/app/models/concerns/ci/deployable.rb @@ -108,6 +108,10 @@ def expanded_kubernetes_namespace end end + def environment_auto_stop_in + options.dig(:environment, :auto_stop_in) if options + end + def expanded_auto_stop_in return unless environment_auto_stop_in diff --git a/app/models/concerns/ci/metadatable.rb b/app/models/concerns/ci/metadatable.rb index 5497d22afdb51e..4e5b89572d3b7d 100644 --- a/app/models/concerns/ci/metadatable.rb +++ b/app/models/concerns/ci/metadatable.rb @@ -21,7 +21,6 @@ module Metadatable delegate :timeout, to: :metadata, prefix: true, allow_nil: true delegate :interruptible, to: :metadata, prefix: false, allow_nil: true - delegate :environment_auto_stop_in, to: :metadata, prefix: false, allow_nil: true delegate :id_tokens, to: :metadata, allow_nil: true delegate :exit_code, to: :metadata, allow_nil: true @@ -67,7 +66,6 @@ def options=(value) ensure_metadata.tap do |metadata| # Store presence of exposed artifacts in build metadata to make it easier to query metadata.has_exposed_artifacts = value&.dig(:artifacts, :expose_as).present? - metadata.environment_auto_stop_in = value&.dig(:environment, :auto_stop_in) end end diff --git a/spec/support/shared_examples/ci/deployable_shared_examples.rb b/spec/support/shared_examples/ci/deployable_shared_examples.rb index 051aac507d4ac3..abbb93f461c64f 100644 --- a/spec/support/shared_examples/ci/deployable_shared_examples.rb +++ b/spec/support/shared_examples/ci/deployable_shared_examples.rb @@ -514,6 +514,21 @@ end end + describe '#environment_auto_stop_in' do + subject { job.environment_auto_stop_in } + + let(:job) { described_class.new(options: options) } + let(:options) { { environment: { auto_stop_in: '1 week' } } } + + it { is_expected.to eq('1 week') } + + context 'when options does not include auto_stop_in' do + let(:options) { { environment: { name: 'production' } } } + + it { is_expected.to be_nil } + end + end + describe '#expanded_auto_stop_in' do let(:job) { create(factory_type, environment: 'environment', options: options, pipeline: pipeline) } let(:options) do -- GitLab