Files
bxh/scripts/backfill_travel_agency_2_0_updated_at.py

48 lines
1.4 KiB
Python

from __future__ import annotations
from datetime import datetime
from falkordb import FalkorDB
GRAPH_NAME = "travel_agency_2_0_test"
UPDATED_AT = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def main() -> dict[str, int | str]:
graph = FalkorDB(host="localhost", port=6380).select_graph(GRAPH_NAME)
node_rows = graph.query(
"""
MATCH (n)
WHERE n.updated_at IS NULL
SET n.updated_at = $updated_at,
n.timestamp_source = 'backfilled_missing_updated_at',
n.timestamp_note = '原始导入未写入更新时间,本次按修正执行时间补齐'
RETURN count(n)
""",
{"updated_at": UPDATED_AT},
).result_set
relation_rows = graph.query(
"""
MATCH ()-[r]->()
WHERE r.updated_at IS NULL
SET r.updated_at = $updated_at,
r.timestamp_source = 'backfilled_missing_updated_at',
r.timestamp_note = '原始导入未写入更新时间,本次按修正执行时间补齐'
RETURN count(r)
""",
{"updated_at": UPDATED_AT},
).result_set
summary = {
"graph": GRAPH_NAME,
"updated_at": UPDATED_AT,
"nodes_backfilled": int(node_rows[0][0] if node_rows else 0),
"relations_backfilled": int(relation_rows[0][0] if relation_rows else 0),
}
print(summary)
return summary
if __name__ == "__main__":
main()