refactor: remove document legacy binding reads
This commit is contained in:
@@ -219,30 +219,15 @@ async def sync_group_bindings_from_doc_type(session, doc_type_id: int, rule_set_
|
||||
group_ids = await ensure_group_for_doc_type(session, doc_type_id)
|
||||
child_group_id = group_ids["child_group_id"]
|
||||
|
||||
legacy_bindings = (
|
||||
await session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT id, rule_set_id, priority, is_active, note
|
||||
FROM leaudit_rule_type_bindings
|
||||
WHERE doc_type_id = :doc_type_id AND deleted_at IS NULL
|
||||
ORDER BY priority DESC, id ASC
|
||||
"""
|
||||
),
|
||||
{"doc_type_id": doc_type_id},
|
||||
)
|
||||
).mappings().all()
|
||||
binding_map = {int(row["rule_set_id"]): row for row in legacy_bindings}
|
||||
payload: list[dict[str, Any]] = []
|
||||
for index, rule_set_id in enumerate(ids):
|
||||
current = binding_map.get(rule_set_id)
|
||||
payload.append(
|
||||
{
|
||||
"id": current.get("id") if current else None,
|
||||
"rule_set_id": rule_set_id,
|
||||
"priority": int(current.get("priority") if current else 100 - index),
|
||||
"is_active": bool(current.get("is_active") if current else True),
|
||||
"note": current.get("note") if current else None,
|
||||
"id": None,
|
||||
"priority": 100 - index,
|
||||
"is_active": True,
|
||||
"note": None,
|
||||
}
|
||||
)
|
||||
await _replace_group_bindings(session, child_group_id, doc_type_id, payload)
|
||||
|
||||
Reference in New Issue
Block a user