Minor style changes.

geändert:       app/models/relation/hierarchy_paths.rb
pull/6851/head
Steffen Kirschke 6 years ago
parent d87075b07e
commit ea01c8ef15
  1. 65
      app/models/relation/hierarchy_paths.rb

@ -86,48 +86,39 @@ module Relation::HierarchyPaths
end
def self.add_hierarchy_path_sql(id = nil)
<<-SQL
INSERT INTO
#{hierarchy_table_name}
(work_package_id, path)
SELECT
to_id, #{add_hierarchy_agg_function} AS path
FROM
(SELECT to_id, from_id, hierarchy FROM relations #{add_conditions_and_union id}) as rel
GROUP BY to_id
#{add_hierarchy_conflict_statement}
SQL
end
def self.add_conditions_and_union(id)
if id.nil?
stmt = <<-SQL
INSERT INTO
#{hierarchy_table_name}
(work_package_id, path)
SELECT
to_id, #{add_hierarchy_agg_function} AS path
FROM
(SELECT to_id, from_id, hierarchy
FROM relations
WHERE hierarchy > 0 AND relates = 0 AND blocks = 0 AND duplicates = 0 AND includes = 0 AND requires = 0 AND follows = 0
) ordered_by_hierarchy
GROUP BY to_id
#{add_hierarchy_conflict_statement}
<<-SQL
WHERE hierarchy > 0 AND relates = 0 AND blocks = 0 AND duplicates = 0 AND includes = 0 AND requires = 0 AND follows = 0
SQL
else
stmt = <<-SQL
INSERT INTO
#{hierarchy_table_name}
(work_package_id, path)
SELECT
to_id, #{add_hierarchy_agg_function} AS path
FROM (
SELECT to_id, from_id, hierarchy
FROM relations
WHERE to_id = #{id} AND
hierarchy > 0 AND relates = 0 AND blocks = 0 AND duplicates = 0 AND includes = 0 AND requires = 0 AND follows = 0
UNION SELECT to_id,from_id,hierarchy
FROM relations
WHERE from_id=#{id} AND
hierarchy > 0 AND relates = 0 AND blocks = 0 AND duplicates = 0 AND includes = 0 AND requires = 0 AND follows = 0
UNION SELECT b.to_id, b.from_id, b.hierarchy FROM relations a
JOIN relations b ON b.to_id = a.to_id
WHERE a.from_id = #{id} AND
a.hierarchy > 0 AND a.relates = 0 AND a.blocks = 0 AND a.duplicates = 0 AND a.includes = 0 AND a.requires = 0 AND a.follows = 0 AND
b.hierarchy > 0 AND b.relates = 0 AND b.blocks = 0 AND b.duplicates = 0 AND b.includes = 0 AND b.requires = 0 AND b.follows = 0
) AS Foo
GROUP BY to_id
#{add_hierarchy_conflict_statement}
<<-SQL
WHERE to_id = #{id} AND
hierarchy > 0 AND relates = 0 AND blocks = 0 AND duplicates = 0 AND includes = 0 AND requires = 0 AND follows = 0
UNION SELECT to_id,from_id,hierarchy
FROM relations
WHERE from_id=#{id} AND
hierarchy > 0 AND relates = 0 AND blocks = 0 AND duplicates = 0 AND includes = 0 AND requires = 0 AND follows = 0
UNION SELECT b.to_id, b.from_id, b.hierarchy FROM relations a
JOIN relations b ON b.to_id = a.to_id
WHERE a.from_id = #{id} AND
a.hierarchy > 0 AND a.relates = 0 AND a.blocks = 0 AND a.duplicates = 0 AND a.includes = 0 AND a.requires = 0 AND a.follows = 0 AND
b.hierarchy > 0 AND b.relates = 0 AND b.blocks = 0 AND b.duplicates = 0 AND b.includes = 0 AND b.requires = 0 AND b.follows = 0
SQL
end
stmt
end
def self.remove_hierarchy_path_sql(id = nil)

Loading…
Cancel
Save