Skip to main content

find_dangling_relationship_ids

Function find_dangling_relationship_ids 

Source
pub fn find_dangling_relationship_ids(
    conn: &Connection,
    namespace: Option<&str>,
) -> Result<Vec<i64>, AppError>
Expand description

Finds relationship rows whose source_id or target_id has no entity.

Distinct from find_orphan_entity_ids, which finds entities carrying no edges. This is the mirror image: edges carrying no entity. Both are called “orphans” and only the first had a repair path, so a database holding a dangling edge had no supported way to clean it — while PRAGMA foreign_key_check reported it on every migration, and ensure_db_ready migrates on open.

Such rows cannot be written while enforcement is on. They exist in files that predate it, or that were written while PRAGMA foreign_keys = OFF was in effect for a schema rebuild.

Namespace-scoped through the relationship’s own column, so repairing one project never reaches another’s edges.

§Errors

Returns AppError::Database when the underlying SQLite operation fails.