@@ -54,12 +54,13 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
54
54
// ------------------------------
55
55
// only make IS_PART_OF updates if node is ADDED or REMOVED
56
56
// ------------------------------
57
+ WITH n, node_diff_map, node_rel_status
57
58
WHERE node_rel_status IS NOT NULL
58
59
MATCH (root:Root)
59
60
// ------------------------------
60
61
// set IS_PART_OF.to, optionally, target branch
61
62
// ------------------------------
62
- WITH root
63
+ WITH root, n, node_rel_status
63
64
CALL (root, n, node_rel_status) {
64
65
OPTIONAL MATCH (root)<-[target_r_root:IS_PART_OF {branch: $target_branch, status: "active"}]-(n)
65
66
WHERE node_rel_status = "deleted"
@@ -69,7 +70,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
69
70
// ------------------------------
70
71
// create new IS_PART_OF relationship on target_branch
71
72
// ------------------------------
72
- WITH root
73
+ WITH root, n, node_rel_status
73
74
CALL (root, n, node_rel_status) {
74
75
OPTIONAL MATCH (root)<-[r_root:IS_PART_OF {branch: $target_branch}]-(n)
75
76
WHERE r_root.status = node_rel_status
@@ -85,6 +86,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
85
86
// shortcut to delete all attributes and relationships for this node if the node is deleted
86
87
// ------------------------------
87
88
CALL (n, node_rel_status) {
89
+ WITH n, node_rel_status
88
90
WHERE node_rel_status = "deleted"
89
91
CALL (n) {
90
92
OPTIONAL MATCH (n)-[rel1:IS_RELATED]-(:Relationship)-[rel2]-(p)
@@ -113,6 +115,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
113
115
// ------------------------------
114
116
// and delete HAS_OWNER and HAS_SOURCE edges to this node if the node is deleted
115
117
// ------------------------------
118
+ WITH n
116
119
CALL (n) {
117
120
CALL (n) {
118
121
MATCH (n)<-[rel:HAS_OWNER]-()
@@ -133,6 +136,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
133
136
}
134
137
}
135
138
}
139
+ WITH n, node_diff_map
136
140
CALL (n, node_diff_map) {
137
141
WITH CASE
138
142
WHEN node_diff_map.attributes IS NULL OR node_diff_map.attributes = [] THEN [NULL]
@@ -155,7 +159,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
155
159
ORDER BY has_attr.from DESC
156
160
LIMIT 1
157
161
}
158
- WITH attr_rel_status, a
162
+ WITH n, attr_rel_status, a
159
163
// ------------------------------
160
164
// set HAS_ATTRIBUTE.to on target branch if necessary
161
165
// ------------------------------
@@ -167,11 +171,12 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
167
171
AND target_r_attr.from <= $at AND target_r_attr.to IS NULL
168
172
SET target_r_attr.to = $at
169
173
}
170
- WITH attr_rel_status, a
174
+ WITH n, attr_rel_status, a
171
175
// ------------------------------
172
176
// conditionally create new HAS_ATTRIBUTE relationship on target_branch, if necessary
173
177
// ------------------------------
174
178
CALL (n, attr_rel_status, a) {
179
+ WITH n, attr_rel_status, a
175
180
WHERE a IS NOT NULL
176
181
OPTIONAL MATCH (n)-[r_attr:HAS_ATTRIBUTE {branch: $target_branch}]->(a)
177
182
WHERE r_attr.status = attr_rel_status
@@ -185,6 +190,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
185
190
}
186
191
RETURN 1 AS done
187
192
}
193
+ WITH n, node_diff_map
188
194
CALL (n, node_diff_map) {
189
195
UNWIND node_diff_map.relationships AS relationship_diff_map
190
196
// ------------------------------
@@ -223,7 +229,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
223
229
source_r_rel_1.hierarchy AS r1_hierarchy,
224
230
source_r_rel_2.hierarchy AS r2_hierarchy
225
231
}
226
- WITH r, r1_dir, r2_dir, r1_hierarchy, r2_hierarchy, rel_name, rel_peer_id, related_rel_status
232
+ WITH n, r, r1_dir, r2_dir, r1_hierarchy, r2_hierarchy, rel_name, rel_peer_id, related_rel_status
227
233
CALL (n, rel_name, rel_peer_id, related_rel_status) {
228
234
OPTIONAL MATCH (n)
229
235
-[target_r_rel_1:IS_RELATED {branch: $target_branch, status: "active"}]
@@ -236,7 +242,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
236
242
SET target_r_rel_1.to = $at
237
243
SET target_r_rel_2.to = $at
238
244
}
239
- WITH r, r1_dir, r2_dir, r1_hierarchy, r2_hierarchy, rel_name, rel_peer_id, related_rel_status
245
+ WITH n, r, r1_dir, r2_dir, r1_hierarchy, r2_hierarchy, rel_name, rel_peer_id, related_rel_status
240
246
// ------------------------------
241
247
// conditionally create new IS_RELATED relationships on target_branch, if necessary
242
248
// ------------------------------
@@ -258,24 +264,28 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
258
264
// create IS_RELATED relationships with directions maintained from source
259
265
// ------------------------------
260
266
CALL (n, r, r1_dir, r1_hierarchy, related_rel_status) {
267
+ WITH n, r, r1_dir, r1_hierarchy, related_rel_status
261
268
WHERE r1_dir = "r"
262
269
CREATE (n)
263
270
-[:IS_RELATED {branch: $target_branch, branch_level: $branch_level, from: $at, status: related_rel_status, hierarchy: r1_hierarchy}]
264
271
->(r)
265
272
}
266
273
CALL (n, r, r1_dir, r1_hierarchy, related_rel_status) {
274
+ WITH n, r, r1_dir, r1_hierarchy, related_rel_status
267
275
WHERE r1_dir = "l"
268
276
CREATE (n)
269
277
<-[:IS_RELATED {branch: $target_branch, branch_level: $branch_level, from: $at, status: related_rel_status, hierarchy: r1_hierarchy}]
270
278
-(r)
271
279
}
272
280
CALL (r, p, r2_dir, r2_hierarchy, related_rel_status) {
281
+ WITH r, p, r2_dir, r2_hierarchy, related_rel_status
273
282
WHERE r2_dir = "r"
274
283
CREATE (r)
275
284
-[:IS_RELATED {branch: $target_branch, branch_level: $branch_level, from: $at, status: related_rel_status, hierarchy: r2_hierarchy}]
276
285
->(p)
277
286
}
278
287
CALL (r, p, r2_dir, r2_hierarchy, related_rel_status) {
288
+ WITH r, p, r2_dir, r2_hierarchy, related_rel_status
279
289
WHERE r2_dir = "l"
280
290
CREATE (r)
281
291
<-[:IS_RELATED {branch: $target_branch, branch_level: $branch_level, from: $at, status: related_rel_status, hierarchy: r2_hierarchy}]
@@ -389,7 +399,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
389
399
}
390
400
RETURN COALESCE (peer, bool, av) AS prop_node
391
401
}
392
- WITH property_diff.property_type AS prop_type, prop_node, CASE
402
+ WITH attr_rel, property_diff.property_type AS prop_type, prop_node, CASE
393
403
WHEN property_diff.action = "ADDED" THEN "active"
394
404
WHEN property_diff.action = "REMOVED" THEN "deleted"
395
405
ELSE NULL
@@ -416,29 +426,34 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
416
426
AND (r_prop.to > $at OR r_prop.to IS NULL)
417
427
RETURN r_prop
418
428
}
419
- WITH prop_rel_status, prop_type, prop_node, r_prop
429
+ WITH attr_rel, prop_rel_status, prop_type, prop_node, r_prop
420
430
WHERE r_prop IS NULL
421
431
// ------------------------------
422
432
// create new edge to prop_node on target_branch, if necessary
423
433
// one subquery per possible edge type b/c edge type cannot be a variable
424
434
// ------------------------------
425
435
CALL (attr_rel, prop_rel_status, prop_type, prop_node) {
436
+ WITH attr_rel, prop_rel_status, prop_type, prop_node
426
437
WHERE prop_type = "HAS_VALUE"
427
438
CREATE (attr_rel)-[:HAS_VALUE { branch: $target_branch, branch_level: $branch_level, from: $at, status: prop_rel_status }]->(prop_node)
428
439
}
429
440
CALL (attr_rel, prop_rel_status, prop_type, prop_node) {
441
+ WITH attr_rel, prop_rel_status, prop_type, prop_node
430
442
WHERE prop_type = "HAS_SOURCE"
431
443
CREATE (attr_rel)-[:HAS_SOURCE { branch: $target_branch, branch_level: $branch_level, from: $at, status: prop_rel_status }]->(prop_node)
432
444
}
433
445
CALL (attr_rel, prop_rel_status, prop_type, prop_node) {
446
+ WITH attr_rel, prop_rel_status, prop_type, prop_node
434
447
WHERE prop_type = "HAS_OWNER"
435
448
CREATE (attr_rel)-[:HAS_OWNER { branch: $target_branch, branch_level: $branch_level, from: $at, status: prop_rel_status }]->(prop_node)
436
449
}
437
450
CALL (attr_rel, prop_rel_status, prop_type, prop_node) {
451
+ WITH attr_rel, prop_rel_status, prop_type, prop_node
438
452
WHERE prop_type = "IS_VISIBLE"
439
453
CREATE (attr_rel)-[:IS_VISIBLE { branch: $target_branch, branch_level: $branch_level, from: $at, status: prop_rel_status }]->(prop_node)
440
454
}
441
455
CALL (attr_rel, prop_rel_status, prop_type, prop_node) {
456
+ WITH attr_rel, prop_rel_status, prop_type, prop_node
442
457
WHERE prop_type = "IS_PROTECTED"
443
458
CREATE (attr_rel)-[:IS_PROTECTED { branch: $target_branch, branch_level: $branch_level, from: $at, status: prop_rel_status }]->(prop_node)
444
459
}
0 commit comments