Constraint enforcement strategies
The referential integrity gap
Section titled “The referential integrity gap”Obsidian vaults have no foreign keys, no cascade deletes, no schema validation on write. When Crosswalker generates 500 interconnected notes, nothing prevents a user from deleting one and leaving broken WikiLinks everywhere. This is the fundamental constraint of file-based graph databases.
Understanding constraint enforcement strategies helps Crosswalker design for resilience rather than hoping for perfect consistency.
Types of integrity violations
Section titled “Types of integrity violations”| Type | Definition | Example |
|---|---|---|
| Dangling reference | Link points to non-existent file | related:: [[Deleted-Control]] |
| Orphan record | File exists with no incoming references | A control note that nothing links to |
| Stale reference | Link points to correct file but data is outdated | Crosswalk link to old framework version |
| Asymmetric relationship | A references B but B doesn’t reference A back | Forward link exists, backlink missing |
Enforcement strategies
Section titled “Enforcement strategies”Eager enforcement (prevent)
Section titled “Eager enforcement (prevent)”Validate constraints before allowing operations. Block invalid states.
| Approach | Example | Feasibility |
|---|---|---|
| Pre-import validation | Check all referenced files exist before generating | Easy — current Crosswalker behavior |
| Schema validation | Reject notes with invalid _crosswalker metadata | Easy — at generation time |
| Pre-delete hooks | Warn before deleting a note with inbound links | Requires plugin — scripts can’t intercept |
| Interactive modals | ”This control has 5 evidence links. Delete anyway?” | Requires plugin |
Limitation: Scripts and import wizards can only enforce eagerly at import time. User actions in the vault (delete, rename, move) cannot be intercepted without a plugin.
Lazy enforcement (detect)
Section titled “Lazy enforcement (detect)”Allow operations, then audit for violations periodically.
| Approach | Example | Complexity |
|---|---|---|
| Post-import scan | Flag notes with broken WikiLinks after re-import | Medium |
| Scheduled audit | Periodic script checking all _crosswalker notes | Medium |
| Bases views | .base file showing notes with stale import_date | Low |
| Backlink analysis | Find framework notes with zero backlinks (unused) | Low |
Obsidian Bases for lazy detection:
Bases limitationObsidian Bases can only do tabular views of frontmatter properties. It cannot traverse typed links, check edge metadata, or do graph queries. Use DataviewJS or Datacore for relationship-level integrity checks.
Compensating transactions (undo/repair)
Section titled “Compensating transactions (undo/repair)”Repair invalid states after they occur.
| Approach | Example | Complexity |
|---|---|---|
| Re-import | Regenerate all notes from source data | Low (destructive to user edits) |
| Link repair script | Find broken WikiLinks and remove/update them | Medium |
| Archive pattern | Move orphaned notes to _archive/ instead of deleting | Low |
| ID aliasing | Add aliases frontmatter for renamed controls | Low |
| Deprecation marking | Set _crosswalker.status: deprecated | Low |
Progressive enhancement path
Section titled “Progressive enhancement path”| Phase | Enforcement | Capability |
|---|---|---|
| Current (0.1.x) | Manual | User reviews generated output |
| Near-term | Lazy detection | Bases views for stale/orphaned notes |
| Medium-term | Import-time eager | Wizard validates before generating |
| Long-term (plugin) | Interactive eager | Modals for destructive actions |
| Future | Full compensation | Undo, rollback, migration wizard |
Metadata tiers
Section titled “Metadata tiers”Inspired by the DFD-Excalidraw project’s progressive metadata approach, Crosswalker’s _crosswalker metadata can be enriched in tiers:
Tier 1: Minimal (current)
Section titled “Tier 1: Minimal (current)”Enables: basic provenance, re-import detection.
Tier 2: Standard (near-term)
Section titled “Tier 2: Standard (near-term)”Enables: version tracking, staleness detection, soft delete.
Tier 3: Extended (medium-term)
Section titled “Tier 3: Extended (medium-term)”Enables: ID aliasing, schema migration, tool version tracking.
Tier 4: Temporal (future)
Section titled “Tier 4: Temporal (future)”Enables: full audit trail, point-in-time queries, rollback. See event sourcing in consistency models.
Orphan detection mechanisms
Section titled “Orphan detection mechanisms”When frameworks update or notes are deleted, orphaned records accumulate. Four detection mechanisms with different performance characteristics:
| Mechanism | Algorithm | Performance | Detects |
|---|---|---|---|
| Forward scan | For each note, verify linked targets exist | O(notes × links) | Dangling references |
| Reverse scan | For each note, verify sources reference back | O(notes × refs) | Stale references |
| Reference counting | Maintain _ref_count on each note | O(1) lookup | Orphans (count = 0) |
| Graph traversal | Walk entire graph, find disconnected components | O(nodes + edges) | All orphan types |
Recommendation for Crosswalker:
- Tier 1: Forward scan at import time (check generated links resolve)
- Tier 2: Bases views for backlink-count-based orphan detection
- Tier 3: Full graph traversal audit script (post-import validation)
Schema versioning
Section titled “Schema versioning”Following the DFD-Excalidraw pattern of dfd-asset-v1, Crosswalker notes include a schema identifier in _crosswalker metadata. When the schema evolves:
- New imports use the new schema version
- Old notes retain their original schema version
- A migration script can detect old versions and update them
- SchemaVer (MODEL-REVISION-ADDITION) tracks compatibility
Resources
Section titled “Resources”Database integrity theory
Section titled “Database integrity theory”- Date, C.J. — “Database Design and Relational Theory” (O’Reilly)
- Referential Integrity — Wikipedia overview
Related pages
Section titled “Related pages”- Data model resilience — re-import strategies
- Consistency models — ACID, CAP, BASE
- File-based graph databases — the data model
- Framework versioning — what happens when frameworks update
- Open questions — unresolved design decisions