-
Notifications
You must be signed in to change notification settings - Fork 6
Cascade Impact Simulator
Interactive visualization tool for previewing deletion cascade impacts before execution.
The Cascade Impact Simulator is a powerful feature that provides a theoretical, non-destructive preview of what will happen when you delete rows or tables with foreign key relationships. It helps prevent accidental data loss by showing exactly which rows will be affected by cascade operations.
Key Features:
- π― Interactive Graph Visualization - ReactFlow-powered dependency graph
- π Detailed Impact Analysis - Row counts, cascade depth, severity warnings
- π Multi-Format Export - CSV, JSON, Text, and PDF reports with graph
- π‘οΈ Non-Destructive - Theoretical simulation only, no actual deletion
- π Circular Dependency Detection - Identifies and warns about cycles
Use the Cascade Impact Simulator when:
β
Deleting rows with foreign key relationships
β
Dropping tables that other tables reference
β
Need to understand cascade depth and scope
β
Want to document deletion impact for compliance
β
Unsure about CASCADE behavior
β
Working with complex database schemas
When viewing table data:
- Find the row(s) you want to delete
- Click the delete button/icon
- In the delete confirmation dialog, click "Simulate Cascade Impact"
- Simulator opens with analysis for that specific row
When viewing database tables:
- Select table(s) to delete
- Click "Delete Selected"
- In the confirmation dialog, click "Simulate Cascade Impact"
- Simulator opens with analysis for entire table deletion
When bulk deleting:
- Select multiple tables or rows
- Click delete action
- Each item shows a "Simulate" button
- Click to analyze specific item's impact
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Cascade Impact Simulator [Export βΌ] β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Impact Summary ββββββββββββββββββ
β β’ Total Affected Rows: 203 β ββ
β β’ Maximum Depth: 2 β Interactive ββ
β β’ Tables Affected: 3 β Graph ββ
β β’ Warnings: 1 high severity β Visualizationββ
β β ββ
β β οΈ Warning: High Impact ββββββββββββββββββ
β Deletion will cascade to 202 β
β additional rows across 2 tables β
β β
β [View Detailed Report] [Close] β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Shows key metrics at a glance:
ββββββββββββββββββββββββββββββββββββ
β Impact Summary β
ββββββββββββββββββββββββββββββββββββ€
β Total Affected Rows: 203 β
β Maximum Cascade Depth: 2 β
β Tables Affected: 3 β
β Cascade Paths: 2 β
β β
β β οΈ 1 high severity warning β
ββββββββββββββββββββββββββββββββββββ
Metrics Explained:
Total Affected Rows:
- Includes the target row(s)/table
- Plus all cascaded deletions
- Sum across all affected tables
Maximum Cascade Depth:
- How many "levels" of cascades
- Depth 0: Target only
- Depth 1: Direct dependencies
- Depth 2+: Cascades of cascades
Tables Affected:
- Number of distinct tables impacted
- Includes target table
Cascade Paths:
- Number of distinct cascade relationships
- Each foreign key with CASCADE creates a path
Node Types:
βββββββββββββββ
β posts β β Red: Source (being deleted)
β 1 row β
βββββββββββββββ
βββββββββββββββ
β comments β β Yellow: CASCADE deletion
β 87 rows β
βββββββββββββββ
βββββββββββββββ
β likes β β Blue: SET NULL (not deleted)
β 15 rows β
βββββββββββββββ
βββββββββββββββ
β tags β β Gray: RESTRICT (blocks deletion)
β 3 rows β
βββββββββββββββ
Color Coding:
- π΄ Red - Source table/row being deleted
- π‘ Yellow - CASCADE: Will be deleted
- π΅ Blue - SET NULL: Will be nullified
- βͺ Gray - RESTRICT/NO ACTION: Blocks deletion
Edge Labels:
- Show ON DELETE action (CASCADE, SET NULL, etc.)
- Arrow direction shows dependency flow
- Dashed lines for SET NULL actions
Graph Controls:
- Zoom - Mouse wheel or +/- buttons
- Pan - Click and drag background
- Center - Click "Fit View" button
- Minimap - Overview of full graph (bottom-right corner)
Expand to see complete analysis:
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Affected Tables β
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β posts β
β β’ Action: DELETE (source) β
β β’ Rows Before: 1 β
β β’ Rows After: 0 β
β β’ Depth: 0 β
β β
β comments β
β β’ Action: CASCADE β
β β’ Rows Before: 87 β
β β’ Rows After: 0 β
β β’ Depth: 1 β
β β’ β οΈ High impact: 87 rows deleted β
β β
β likes β
β β’ Action: CASCADE β
β β’ Rows Before: 15 β
β β’ Rows After: 0 β
β β’ Depth: 1 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
Warnings are color-coded by severity:
π΄ High Severity:
- Large number of rows affected (>100)
- Deep cascade chains (depth >3)
- RESTRICT blocking deletion
π‘ Medium Severity:
- Moderate row count (20-100)
- Multiple cascade paths
- SET NULL affecting many rows
π’ Low Severity:
- Small row counts (<20)
- Simple cascade (depth 1-2)
- No blocking constraints
Example Warnings:
β οΈ High Impact (Red)
Deletion will cascade to 152 rows in table 'comments'
β οΈ Circular Dependency (Yellow)
Tables 'users' and 'profiles' have circular foreign keys
β οΈ Constraint Violation (Red)
Table 'audit_logs' has RESTRICT constraint preventing deletion
Step 1: Analyze Foreign Keys
-- For each affected table
PRAGMA foreign_key_list(table_name);Step 2: Build Dependency Graph
- Identifies all foreign key relationships
- Maps CASCADE, SET NULL, RESTRICT, NO ACTION
- Creates directed graph of dependencies
Step 3: Calculate Row Counts
-- For each dependent table
SELECT COUNT(*) FROM dependent_table
WHERE foreign_key_column = target_value;Step 4: Traverse Graph Recursively
- Follows CASCADE relationships
- Calculates depth at each level
- Detects circular dependencies
Step 5: Generate Warnings
- Analyzes row counts
- Checks cascade depth
- Identifies constraints
Important: The simulator performs a theoretical analysis:
β What It Does:
- Analyzes schema relationships
- Counts affected rows
- Predicts cascade behavior
- Shows what would happen
β What It Doesn't Do:
- Actually delete data
- Execute SQL commands
- Modify database
- Guarantee exact results (triggers may affect actual behavior)
Graph Traversal:
1. Start at source node (target row/table)
2. Find all outbound foreign keys (tables this references)
3. Find all inbound foreign keys (tables that reference this)
4. For each CASCADE relationship:
a. Count affected rows
b. Add to affected list
c. Recursively traverse from that node
5. Detect cycles (visited nodes)
6. Calculate maximum depth
7. Generate warnings based on metrics
Circular Dependency Handling:
If node already visited:
- Mark as circular dependency
- Don't traverse again (prevent infinite loop)
- Warn user about cycle
Tabular format for spreadsheet analysis:
Table,Action,Rows Before,Rows After,Depth,Column,Referenced Table
posts,DELETE,1,0,0,,,
comments,CASCADE,87,0,1,post_id,posts
likes,CASCADE,15,0,1,post_id,postsUse Cases:
- Import into Excel/Google Sheets
- Data analysis
- Reporting
- Archiving
Machine-readable format:
{
"targetTable": "posts",
"whereClause": "id = 42",
"totalAffectedRows": 103,
"maxDepth": 1,
"cascadePaths": [
{
"sourceTable": "posts",
"targetTable": "comments",
"action": "CASCADE",
"depth": 1,
"affectedRows": 87,
"column": "post_id"
}
],
"affectedTables": [...],
"warnings": [...],
"timestamp": "2024-11-03T10:30:00Z"
}Use Cases:
- API integration
- Automated processing
- Custom analysis tools
- Version control
Human-readable summary:
Cascade Impact Analysis
Generated: 2024-11-03 10:30:00
Target: posts (id = 42)
βββββββββββββββββββββββββββββββββββββββ
SUMMARY
-------
Total Affected Rows: 103
Maximum Cascade Depth: 1
Tables Affected: 3
Cascade Paths: 2
AFFECTED TABLES
---------------
1. posts
Action: DELETE (source)
Rows: 1 β 0
Depth: 0
2. comments
Action: CASCADE
Rows: 87 β 0
Depth: 1
β οΈ High impact: 87 rows deleted
3. likes
Action: CASCADE
Rows: 15 β 0
Depth: 1
WARNINGS
--------
β οΈ High Impact: Deletion will cascade to 102 additional rows
Use Cases:
- Documentation
- Audit trails
- Email reports
- Review before deletion
Professional report with graph visualization:
Includes:
- Cover page with summary
- Embedded graph visualization (screenshot)
- Detailed table breakdown
- Warnings section
- Timestamp and metadata
Use Cases:
- Compliance documentation
- Management reports
- Archival records
- Change request documentation
Scenario: Delete a user account
Steps:
- Navigate to
userstable - Find user row to delete
- Click delete button
- Click "Simulate Cascade Impact"
- Review graph:
- See all related posts, comments, likes
- Check cascade depth
- Note total affected rows
- Review warnings
- Export PDF for records (optional)
- If acceptable, proceed with deletion
- If not, cancel and clean up dependencies first
Scenario: Drop an unused table
Steps:
- Navigate to database
- Select table to drop
- Click "Delete"
- Click "Simulate Cascade Impact"
- Check for:
- Unexpected dependencies
- RESTRICT constraints blocking deletion
- Circular references
- Review affected tables
- Export report for team review
- Proceed or adjust foreign keys first
Scenario: Document major schema change
Steps:
- Simulate deletion impact
- Export to PDF
- Attach to change request
- Get approval from stakeholders
- Execute deletion
- Archive simulation report
Scenario: Understand table relationships
Steps:
- Simulate deletion of sample row
- View graph visualization
- Understand dependency chain
- Export JSON for documentation
- Cancel deletion (was just for analysis)
Target: Delete blog post (id = 42)
Simulation Results:
Total Affected: 203 rows
Depth: 2
Cascade Path 1:
posts β comments (87 rows)
Cascade Path 2:
posts β likes (15 rows)
Cascade Path 3:
comments β comment_likes (101 rows)
Decision: Proceed, but export comments first for potential restoration.
Target: Delete user (id = 123)
Simulation Results:
Total Affected: 1,245 rows
Depth: 3
β οΈ RESTRICT Constraint Found!
Table: invoices
Cannot delete: RESTRICT on user_id
Recommendation: Archive invoices or change foreign key to SET NULL
Decision: Cancel deletion, adjust schema first.
Target: Delete old test data (status = 'test')
Simulation Results:
Total Affected: 47 rows
Depth: 1
All CASCADE, no warnings
Decision: Safe to proceed with bulk deletion.
Never delete without simulation when:
- Table has foreign keys
- Deleting multiple rows
- Working with production data
- Unfamiliar with schema
Export when:
- Deleting large amounts of data
- Making schema changes
- Need audit trail
- Compliance requirements
High severity warnings require:
- Extra attention
- Stakeholder approval
- Backup before proceeding
- Consideration of alternatives
Benefits:
- Visualize relationships
- Understand dependencies
- Onboard new developers
- Plan schema changes
Workflow:
- Simulate in development environment
- Review and adjust
- Document expected behavior
- Simulate in production
- Compare results
- Proceed if consistent
Note: The simulation does not account for:
- BEFORE DELETE triggers
- AFTER DELETE triggers
- Complex trigger logic
Impact: Actual deletion may differ if triggers modify behavior.
Workaround: Review triggers manually and document separately.
Views depending on deleted data are not shown in simulation.
Workaround: Check view definitions manually:
SELECT sql FROM sqlite_master WHERE type = 'view';If your application code handles cascades (not database), simulator won't detect them.
Workaround: Document application-level logic separately.
Simulating deletion on very large tables (millions of rows) may be slow due to COUNT queries.
Optimization: Consider sampling for very large datasets.
Cause: ReactFlow library not loaded or rendering error.
Solution:
- Refresh page
- Check browser console for errors
- Try different browser
- Report issue if persistent
Cause: Counts cached or database changed.
Solution:
- Re-run simulation
- Ensure database not modified during simulation
- Check for active transactions
Cause: Tables reference each other (legitimate or design issue).
Example:
-- users references profiles
CREATE TABLE users (..., profile_id INT, FOREIGN KEY (profile_id) REFERENCES profiles(id));
-- profiles references users
CREATE TABLE profiles (..., user_id INT, FOREIGN KEY (user_id) REFERENCES users(id));Solution:
- Review schema design
- Consider breaking circular reference
- Document intentional circles
Cause: Large dataset or browser memory limit.
Solution:
- Try different export format
- Close other browser tabs
- Use CSV instead of PDF for large reports
- Export in smaller chunks
POST /api/tables/:dbId/simulate-cascade
Content-Type: application/json
{
"targetTable": "posts",
"whereClause": "id = 42" // Optional, omit for table deletion
}Response:
{
"targetTable": "posts",
"whereClause": "id = 42",
"totalAffectedRows": 103,
"maxDepth": 1,
"cascadePaths": [...],
"affectedTables": [...],
"warnings": [...],
"circularDependencies": []
}See API Reference for complete documentation.
Planned features:
- What-If Analysis - Test different deletion strategies
- Undo Simulation - Preview restoration after deletion
- Historical Reports - Track deletion patterns over time
- Batch Simulation - Analyze multiple deletions at once
- Foreign Key Dependencies - Understanding relationships
- Table Operations - Delete operations
- Database Management - Schema management
- API Reference - Simulation API details
Need Help? See Troubleshooting or open an issue.
- Database Management
- R2 Backup Restore
- Scheduled Backups
- Table Operations
- Query Console
- Schema Designer
- Column Management
- Bulk Operations
- Job History
- Time Travel
- Read Replication
- Undo Rollback
- Foreign Key Visualizer
- ER Diagram
- Foreign Key Dependencies
- Foreign Key Navigation
- Circular Dependency Detector
- Cascade Impact Simulator
- AI Search
- FTS5 Full Text Search
- Cross Database Search
- Index Analyzer
- Database Comparison
- Database Optimization