diff --git a/app/models/ci/pipeline_metadata.rb b/app/models/ci/pipeline_metadata.rb index 2bd206c5ca5d87862e5d0b2ad99a4f06e3cc7762..5457fb899b08085bf2e9e1a5630846cd5defd45a 100644 --- a/app/models/ci/pipeline_metadata.rb +++ b/app/models/ci/pipeline_metadata.rb @@ -4,11 +4,17 @@ module Ci class PipelineMetadata < Ci::ApplicationRecord self.primary_key = :pipeline_id + enum auto_cancel_on_new_commit: { + conservative: 0, + interruptible: 1, + disabled: 2 + }, _prefix: true + belongs_to :pipeline, class_name: "Ci::Pipeline", inverse_of: :pipeline_metadata belongs_to :project, class_name: "Project", inverse_of: :pipeline_metadata validates :pipeline, presence: true validates :project, presence: true - validates :name, presence: true, length: { minimum: 1, maximum: 255 } + validates :name, length: { minimum: 1, maximum: 255 }, allow_nil: true end end diff --git a/db/migrate/20231121092109_remove_ci_pipeline_metadata_name_not_null_constraint.rb b/db/migrate/20231121092109_remove_ci_pipeline_metadata_name_not_null_constraint.rb new file mode 100644 index 0000000000000000000000000000000000000000..de1d4c1bcc9a3551bcbc4d1acd13fd61313b9b38 --- /dev/null +++ b/db/migrate/20231121092109_remove_ci_pipeline_metadata_name_not_null_constraint.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class RemoveCiPipelineMetadataNameNotNullConstraint < Gitlab::Database::Migration[2.2] + milestone '16.7' + + disable_ddl_transaction! + + CONSTRAINT_NAME = 'check_25d23931f1' + + def up + remove_not_null_constraint :ci_pipeline_metadata, :name, constraint_name: CONSTRAINT_NAME + end + + def down + add_not_null_constraint :ci_pipeline_metadata, :name, constraint_name: CONSTRAINT_NAME + end +end diff --git a/db/migrate/20231121092128_add_auto_cancel_on_new_commit_to_ci_pipeline_metadata.rb b/db/migrate/20231121092128_add_auto_cancel_on_new_commit_to_ci_pipeline_metadata.rb new file mode 100644 index 0000000000000000000000000000000000000000..9b698c835535945eb6037b591e38d964073b9335 --- /dev/null +++ b/db/migrate/20231121092128_add_auto_cancel_on_new_commit_to_ci_pipeline_metadata.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddAutoCancelOnNewCommitToCiPipelineMetadata < Gitlab::Database::Migration[2.2] + enable_lock_retries! + milestone '16.7' + + def change + add_column :ci_pipeline_metadata, :auto_cancel_on_new_commit, :smallint, default: 0, null: false + end +end diff --git a/db/schema_migrations/20231121092109 b/db/schema_migrations/20231121092109 new file mode 100644 index 0000000000000000000000000000000000000000..94d937167f7c662ecb0071c5bbdef5662c92c7af --- /dev/null +++ b/db/schema_migrations/20231121092109 @@ -0,0 +1 @@ +22f8ce9668370446060d834b4a1fc8fe45fb5497a8bd9fc0fa7a0dc674416d2d \ No newline at end of file diff --git a/db/schema_migrations/20231121092128 b/db/schema_migrations/20231121092128 new file mode 100644 index 0000000000000000000000000000000000000000..aabcab232456850c737ab794571caee01c4c3607 --- /dev/null +++ b/db/schema_migrations/20231121092128 @@ -0,0 +1 @@ +cb2ecf9b5e917a422f2372edf088ee0568cd1ecfd5d39288b5c641cf1594ad11 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index f2ec5f79486004c8aa3619c862ae9e70671f4982..5ae28d6aae9f17e901c9279535c1072fb93684ab 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -14217,7 +14217,7 @@ CREATE TABLE ci_pipeline_metadata ( project_id bigint NOT NULL, pipeline_id bigint NOT NULL, name text, - CONSTRAINT check_25d23931f1 CHECK ((name IS NOT NULL)), + auto_cancel_on_new_commit smallint DEFAULT 0 NOT NULL, CONSTRAINT check_9d3665463c CHECK ((char_length(name) <= 255)) ); diff --git a/spec/models/ci/pipeline_metadata_spec.rb b/spec/models/ci/pipeline_metadata_spec.rb index 977c90bcc2a43f5a19cf19b120ca4975081467e6..2db7a2c23e91f26151bff760ccfd93688a0a7e70 100644 --- a/spec/models/ci/pipeline_metadata_spec.rb +++ b/spec/models/ci/pipeline_metadata_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::PipelineMetadata do +RSpec.describe Ci::PipelineMetadata, feature_category: :pipeline_composition do it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:pipeline) } @@ -10,5 +10,13 @@ it { is_expected.to validate_length_of(:name).is_at_least(1).is_at_most(255) } it { is_expected.to validate_presence_of(:project) } it { is_expected.to validate_presence_of(:pipeline) } + + it do + is_expected.to define_enum_for( + :auto_cancel_on_new_commit + ).with_values( + conservative: 0, interruptible: 1, disabled: 2 + ).with_prefix + end end end