2020-09-08 11:08:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class PipelineObjectHierarchy < ::Gitlab::ObjectHierarchy
|
|
|
|
private
|
|
|
|
|
|
|
|
def middle_table
|
|
|
|
::Ci::Sources::Pipeline.arel_table
|
|
|
|
end
|
|
|
|
|
|
|
|
def from_tables(cte)
|
|
|
|
[objects_table, cte.table, middle_table]
|
|
|
|
end
|
|
|
|
|
|
|
|
def parent_id_column(_cte)
|
|
|
|
middle_table[:source_pipeline_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def ancestor_conditions(cte)
|
|
|
|
middle_table[:source_pipeline_id].eq(objects_table[:id]).and(
|
|
|
|
middle_table[:pipeline_id].eq(cte.table[:id])
|
2020-09-15 14:09:43 -04:00
|
|
|
).and(
|
2021-06-22 08:08:05 -04:00
|
|
|
project_condition
|
2020-09-08 11:08:41 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def descendant_conditions(cte)
|
|
|
|
middle_table[:pipeline_id].eq(objects_table[:id]).and(
|
|
|
|
middle_table[:source_pipeline_id].eq(cte.table[:id])
|
2020-09-15 14:09:43 -04:00
|
|
|
).and(
|
2021-06-22 08:08:05 -04:00
|
|
|
project_condition
|
2020-09-08 11:08:41 -04:00
|
|
|
)
|
|
|
|
end
|
2020-09-15 14:09:43 -04:00
|
|
|
|
2021-06-22 08:08:05 -04:00
|
|
|
def project_condition
|
|
|
|
case options[:project_condition]
|
|
|
|
when :same then middle_table[:source_project_id].eq(middle_table[:project_id])
|
|
|
|
when :different then middle_table[:source_project_id].not_eq(middle_table[:project_id])
|
|
|
|
else Arel.sql('TRUE')
|
2020-09-15 14:09:43 -04:00
|
|
|
end
|
|
|
|
end
|
2020-09-08 11:08:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|