Relations¶
Relation declarations between tables for cascade-cleanup and FK validation.
A Relation captures a foreign-key reference from one table’s column(s)
to another table’s column(s). Relations are typically derived from
Column.foreign_key declarations on user schemas via
resolve_relations_from_schemas(), but can also be constructed explicitly
to override or extend the schema-derived set.
- class algomancy_data.relations.Relation(child_table, child_cols, parent_table, parent_cols, parent_requires_child=False, track_partial_loss=False)[source]¶
Bases:
objectA foreign-key relation between a child table and a parent table.
Used by
CascadeDropTransformer(cascade cleanup) andForeignKeyValidator.from_schemas(FK violation reporting). Typically built fromColumn.foreign_keydeclarations viaresolve_relations_from_schemas(), but can be constructed explicitly to override or extend the schema-derived set.- child_table: str¶
Logical name of the child table (matches
Schema.file_name()).
- child_cols: Tuple[str, ...]¶
Tuple of column names on the child table that form the FK.
- parent_table: str¶
Logical name of the parent (referenced) table.
- parent_cols: Tuple[str, ...]¶
Tuple of column names on the parent table forming the referenced key.
- parent_requires_child: bool = False¶
If True, parents with zero referencing children are dropped.
- track_partial_loss: bool = False¶
If True, enables partial-loss cascade when paired with a snapshot.
- property key: Tuple[str, Tuple[str, ...]]¶
(child_table, child_cols).- Type:
Identity used when merging relations
- algomancy_data.relations.resolve_relations_from_schemas(schemas)[source]¶
Build a list of
Relationobjects from FK declarations on schemas.Walks the
Column.foreign_keydeclarations on each schema and groups columns sharing the same parent table into composite FKs. Within a single schema, all columns withforeign_keypointing at the same parent table are collapsed into one composite relation; the referenced parent columns are taken from each column’sforeign_keytuple in declaration order.
- algomancy_data.relations.merge_relations(base, override)[source]¶
Merge two relation lists;
overridewins on matching(child_table, child_cols).- Parameters:
- Returns:
Combined list. Entries from
overridereplace entries frombasewith the samekey; remaining entries fromoverrideare appended.- Return type:
List[Relation]