diff options
Diffstat (limited to 'app/models/ci/sources/pipeline.rb')
-rw-r--r-- | app/models/ci/sources/pipeline.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/models/ci/sources/pipeline.rb b/app/models/ci/sources/pipeline.rb index 2df504cd3de..855e68d1db1 100644 --- a/app/models/ci/sources/pipeline.rb +++ b/app/models/ci/sources/pipeline.rb @@ -3,6 +3,7 @@ module Ci module Sources class Pipeline < Ci::ApplicationRecord + include Ci::Partitionable include Ci::NamespacedModelName self.table_name = "ci_sources_pipelines" @@ -15,6 +16,11 @@ module Ci belongs_to :source_bridge, class_name: "Ci::Bridge", foreign_key: :source_job_id belongs_to :source_pipeline, class_name: "Ci::Pipeline", foreign_key: :source_pipeline_id + partitionable scope: :pipeline + + before_validation :set_source_partition_id, on: :create + validates :source_partition_id, presence: true + validates :project, presence: true validates :pipeline, presence: true @@ -23,6 +29,15 @@ module Ci validates :source_pipeline, presence: true scope :same_project, -> { where(arel_table[:source_project_id].eq(arel_table[:project_id])) } + + private + + def set_source_partition_id + return if source_partition_id_changed? && source_partition_id.present? + return unless source_job + + self.source_partition_id = source_job.partition_id + end end end end |