@@ -44,7 +44,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
4444 MATCH (source_artifact)-[r:IS_PART_OF]->(:Root)
4545 WHERE %(source_branch_filter)s
4646 RETURN r AS root_rel
47- ORDER BY r.branch_level DESC, r.from DESC
47+ ORDER BY r.branch_level DESC, r.from DESC, r.status ASC
4848 LIMIT 1
4949}
5050WITH source_artifact, root_rel
@@ -61,7 +61,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
6161 target_node,
6262 (rrel1.status = "active" AND rrel2.status = "active") AS target_is_active,
6363 $source_branch_name IN [rrel1.branch, rrel2.branch] AS target_on_source_branch
64- ORDER BY rrel1.branch_level DESC, rrel1 .branch_level DESC, rrel1.from DESC, rrel2.from DESC
64+ ORDER BY rrel1.branch_level DESC, rrel2 .branch_level DESC, rrel1.from DESC, rrel2.from DESC, rrel1.status ASC, rrel2.status ASC
6565 LIMIT 1
6666 }
6767 // -----------------------
@@ -75,7 +75,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
7575 definition_node,
7676 (rrel1.status = "active" AND rrel2.status = "active") AS definition_is_active,
7777 $source_branch_name IN [rrel1.branch, rrel2.branch] AS definition_on_source_branch
78- ORDER BY rrel1.branch_level DESC, rrel1 .branch_level DESC, rrel1.from DESC, rrel2.from DESC
78+ ORDER BY rrel1.branch_level DESC, rrel2 .branch_level DESC, rrel1.from DESC, rrel2.from DESC, rrel1.status ASC, rrel2.status ASC
7979 LIMIT 1
8080 }
8181 // -----------------------
@@ -89,7 +89,8 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
8989 attr_val.value AS checksum,
9090 (attr_rel.status = "active" AND value_rel.status = "active") AS checksum_is_active,
9191 $source_branch_name IN [attr_rel.branch, value_rel.branch] AS checksum_on_source_branch
92- ORDER BY value_rel.branch_level DESC, attr_rel.branch_level DESC, value_rel.from DESC, attr_rel.from DESC
92+ ORDER BY value_rel.branch_level DESC, attr_rel.branch_level DESC, value_rel.from DESC, attr_rel.from DESC,
93+ value_rel.status ASC, attr_rel.status ASC
9394 LIMIT 1
9495 }
9596 // -----------------------
@@ -103,7 +104,8 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
103104 attr_val.value AS storage_id,
104105 (attr_rel.status = "active" AND value_rel.status = "active") AS storage_id_is_active,
105106 $source_branch_name IN [attr_rel.branch, value_rel.branch] AS storage_id_on_source_branch
106- ORDER BY value_rel.branch_level DESC, attr_rel.branch_level DESC, value_rel.from DESC, attr_rel.from DESC
107+ ORDER BY value_rel.branch_level DESC, attr_rel.branch_level DESC, value_rel.from DESC, attr_rel.from DESC,
108+ value_rel.status ASC, attr_rel.status ASC
107109 LIMIT 1
108110 }
109111 WITH target_node, target_is_active, target_on_source_branch,
@@ -147,7 +149,8 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
147149 RETURN
148150 target_artifact,
149151 (trel1.status = "active" AND trel2.status = "active" AND drel1.status = "active" AND drel1.status = "active") AS artifact_is_active
150- ORDER BY trel1.from DESC, trel2.from DESC, drel1.from DESC, drel2.from DESC
152+ ORDER BY trel1.from DESC, trel2.from DESC, drel1.from DESC, drel2.from DESC,
153+ trel1.status ASC, trel2.status ASC, drel1.status ASC, drel2.status ASC
151154 LIMIT 1
152155 }
153156 WITH CASE
@@ -163,7 +166,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
163166 AND attr_rel.branch = $target_branch_name
164167 AND value_rel.branch = $target_branch_name
165168 RETURN attr_val.value AS checksum, (attr_rel.status = "active" AND value_rel.status = "active") AS checksum_is_active
166- ORDER BY value_rel.from DESC, attr_rel.from DESC
169+ ORDER BY value_rel.from DESC, attr_rel.from DESC, value_rel.status ASC, attr_rel.status ASC
167170 LIMIT 1
168171 }
169172 // -----------------------
@@ -175,7 +178,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
175178 AND attr_rel.branch = $target_branch_name
176179 AND value_rel.branch = $target_branch_name
177180 RETURN attr_val.value AS storage_id, (attr_rel.status = "active" AND value_rel.status = "active") AS storage_id_is_active
178- ORDER BY value_rel.from DESC, attr_rel.from DESC
181+ ORDER BY value_rel.from DESC, attr_rel.from DESC, value_rel.status ASC, attr_rel.status ASC
179182 LIMIT 1
180183 }
181184 RETURN target_artifact,
0 commit comments