Collection hierarchy implementation¶
For collection creation, moves, and inherited access, see the collection guide.
Persistence and authorization¶
The database stores hierarchy in two places:
collections.parent_collection_idstores the direct tree edgecollection_closurestores every ancestor-to-descendant path, including the self row at depth0
Authorization joins permission rows through collection_closure: a permission
row on an ancestor is matched to the descendant collection being checked. The
authorization path preserves the existing combined-permission invariant by
filtering a single permission row for all requested flags and then counting the
distinct target descendants covered by matching rows.
Create and import paths must call the shared collection insert helper so the
closure table receives the self row and inherited ancestor rows in the same
transaction as the collection row. Move operations update parent_collection_id
and rebuild only the closure rows that connect the moved subtree to ancestors
outside that subtree.
The hierarchy implementation intentionally remains inside the PostgreSQL storage adapter rather than the root application or backend-neutral contract. It depends on Diesel table definitions, PostgreSQL-specific closure-table SQL, temporal history, and permission semantics. Other storage adapters must preserve the same observable hierarchy contract but may use a different persistence representation.
Performance-sensitive queries rely on these indexes:
permissions_group_collection_idxfor principal/group permission lookupscollections_parent_idxfor child listings and delete checkscollection_closure_descendant_ancestor_depth_idxfor effective permission explanations and target-descendant authorization checkscollection_closure_ancestor_depth_idxfor subtree scans and move rewrites