pgapi-enforces-referential-integrity-bidirectionally
IN derived (depth 1)
PgApi enforces referential integrity in both directions: write-time validation checks all antecedent and outlist IDs exist before inserting justifications, while read-time dependent discovery queries both antecedent and outlist JSONB containment to find all affected nodes.
Summary
The database layer protects the consistency of the justification network from both sides. Before saving a new justification, it confirms that every referenced node actually exists, and when something changes, it knows how to find every node that depends on the changed one — whether through normal antecedent links or outlist links. This matters because the underlying storage uses JSONB arrays that cannot enforce foreign keys on their own, so the application has to do that work itself to prevent dangling references and missed propagation.
Justifications
SL — Write-time validation and read-time discovery are complementary halves of PgApi's referential integrity enforcement
Antecedents (all must be IN):
- pgapi-validates-refs-before-justification-insert — PgApi's `_validate_refs` checks all antecedent and outlist node IDs exist in `rms_nodes` before inserting a justification, providing application-level referential integrity that compensates for JSONB arrays' inability to enforce foreign key constraints.
- pgapi-find-dependents-queries-outlist — PgApi's `_find_dependents` queries both `antecedents @>` and `outlist @>` JSONB containment, correctly enqueuing outlist-dependent nodes for re-evaluation — a capability the in-memory Network historically lacked until PR #31.
Dependents
These beliefs depend on this one:
- pg-data-integrity-achieves-defense-in-depth — PgApi's data integrity achieves defense-in-depth through both application-level enforcement (write-time referential validation and outlist-aware dependent queries spanning antecedent and outlist references) and comprehensive input validation at all system boundaries, but full defense-in-depth requires database-level foreign key constraints to provide a second independent enforcement layer
- pgapi-referential-integrity-is-database-enforced — PgApi achieves complete referential integrity: application-level bidirectional enforcement (write-time validation and outlist-aware dependent querying) is complemented by database-level foreign key constraints, preventing orphaned justification references even under direct SQL manipulation outside the application layer.