Skip to content

Commit

Permalink
account for branches
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtmccarty committed Nov 17, 2024
1 parent 9fe9a03 commit 2991f3f
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions backend/infrahub/core/query/relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs) -> None:
self.params["destination_id"] = self.destination_id
self.params["rel_id"] = self.rel.id
self.params["branch"] = self.branch.name
self.params["branch_level"] = self.branch.hierarchy_level
self.params["branch_names"] = self.branch.get_branches_in_scope()
self.params["rel_prop"] = self.get_relationship_properties_dict(status=RelationshipStatus.DELETED)
self.params["at"] = self.at.to_string()

Expand All @@ -455,30 +455,50 @@ async def query_init(self, db: InfrahubDatabase, **kwargs) -> None:
CALL {
WITH rl
MATCH (rl)-[edge:IS_VISIBLE]->(visible)
WHERE edge.to IS NULL AND edge.status = "active"
SET edge.to = $at
WHERE edge.branch IN $branch_names AND edge.to IS NULL AND edge.status = "active"
WITH rl, edge, visible
ORDER BY edge.branch_level DESC
LIMIT 1
CREATE (rl)-[deleted_edge:IS_VISIBLE $rel_prop]->(visible)
WITH edge
WHERE edge.branch = $branch
SET edge.to = $at
}
CALL {
WITH rl
MATCH (rl)-[edge:IS_PROTECTED]->(protected)
WHERE edge.to IS NULL AND edge.status = "active"
SET edge.to = $at
WHERE edge.branch IN $branch_names AND edge.to IS NULL AND edge.status = "active"
WITH rl, edge, protected
ORDER BY edge.branch_level DESC
LIMIT 1
CREATE (rl)-[deleted_edge:IS_PROTECTED $rel_prop]->(protected)
WITH edge
WHERE edge.branch = $branch
SET edge.to = $at
}
CALL {
WITH rl
MATCH (rl)-[edge:HAS_OWNER]->(owner_node)
WHERE edge.to IS NULL AND edge.status = "active"
SET edge.to = $at
WHERE edge.branch IN $branch_names AND edge.to IS NULL AND edge.status = "active"
WITH rl, edge, owner_node
ORDER BY edge.branch_level DESC
LIMIT 1
CREATE (rl)-[deleted_edge:HAS_OWNER $rel_prop]->(owner_node)
WITH edge
WHERE edge.branch = $branch
SET edge.to = $at
}
CALL {
WITH rl
MATCH (rl)-[edge:HAS_SOURCE]->(source_node)
WHERE edge.to IS NULL AND edge.status = "active"
SET edge.to = $at
WHERE edge.branch IN $branch_names AND edge.to IS NULL AND edge.status = "active"
WITH rl, edge, source_node
ORDER BY edge.branch_level DESC
LIMIT 1
CREATE (rl)-[deleted_edge:HAS_SOURCE $rel_prop]->(source_node)
WITH edge
WHERE edge.branch = $branch
SET edge.to = $at
}
""" % (
r1,
Expand Down

0 comments on commit 2991f3f

Please sign in to comment.