What this is
A small script combining this tier's two traversal-shaping tools, edge_types and filter, into one reporting-structure report for a person: their full management chain up to the top, and which of their direct/indirect reports are senior enough (3+ years) to matter for a succession conversation.
What it does
management_chain(conn, person_id) walks reports_to outward (subordinate to manager to manager's manager) with graph.traverse(), unfiltered, since you want the whole chain regardless of seniority. senior_reports(conn, person_id, min_years) walks the same edge type *inward* (manager to reports), this time with a graph.gte() filter on seniority_years. main() runs both for Dan and prints a small report.
Where each piece came from
- Schema setup (companies with subsidiaries, people with a reporting chain, projects), table/edge/filter-column registration,
graph.build()- Lesson 10'ssetup_and_build(), reused as-is. management_chain()-graph.traverse()withedge_types := ARRAY['reports_to'],direction := 'out', from Lesson 10.senior_reports()- the same call shape,direction := 'in', plusfilter := graph.gte('seniority_years', min_years)from Lesson 11.
Try this yourself
- Give Dan a direct report in
setup_and_build()(add a person withmanager_id := 'p4') and confirm they show up insenior_reports(conn, 'p4', 3)if their seniority qualifies. - Lower
min_yearsto1for Alice's report and confirm Dan (2 years, her indirect report) now appears too. - Try
management_chainon Eve (p5), who has no manager set, and confirm it returns an empty list rather than erroring.
If anything here still feels unclear, ask before moving to Lesson 20.