MY PROP JOURNAL

CASCADE Deletes Safety Guide

Understanding CASCADE delete operations and their impact on related data

CRITICAL: DELETE operations in this API are permanent and immediate. Related data is automatically deleted (CASCADE) or unlinked (SET NULL) when you delete a parent resource. These operations cannot be undone.

What Are CASCADE Deletes?

CASCADE deletes automatically delete or modify related records when you delete a parent record. This ensures data integrity by preventing orphaned records.

Key Points:

  • ✅ Prevents orphaned data
  • ⚠️ Cannot be undone
  • 📊 Responses include warnings showing what was affected
  • 🚨 Some operations (Accounts, Tag Groups, Strategies) delete large amounts of data

How CASCADE Deletes Work

When you delete a resource through the API:

  1. The API validates the delete operation
  2. CASCADE rules automatically delete related records
  3. SET NULL rules automatically unlink references in other records
  4. API response includes warnings about what was affected

Example DELETE Response

{
  "success": true,
  "message": "Trade deleted successfully",
  "warnings": [
    "3 execution(s) deleted",
    "1 trade write-up(s) deleted",
    "2 tag association(s) deleted"
  ]
}

Impact by Resource

🚨 HIGH RISK Operations

These deletions affect large amounts of data and should be performed with extreme caution.

Deleting an Account

Will DELETE (CASCADE):

  • All trades associated with the account
  • All executions from those trades
  • All payouts for the account
  • All documents for the account
  • All tag associations

Cascade Delete Warning

Deleting an account will permanently delete all trading history, executions, payouts, and documents associated with that account. This operation affects potentially hundreds or thousands of records.

Before deleting an account:

  1. Export all trade data
  2. Download all documents
  3. Verify you have backups
  4. Consider archiving instead of deleting

Deleting a Tag Group

Will DELETE (CASCADE):

  • All tags within the group
  • All tag associations across all resources (trades, write-ups, plans, strategies, etc.)

Cascade Delete Warning

Deleting a tag group will delete all tags in that group and remove those tags from all trades, write-ups, strategies, playbooks, report cards, chart books, trading plans, and accounts where they were applied.


⚠️ MEDIUM RISK Operations

These operations affect moderate amounts of data and related resources.

Deleting a Trade

Will DELETE (CASCADE):

  • All executions for the trade
  • Associated trade write-up (if any)
  • All tag associations

Will SET NULL:

  • None (executions are fully owned by the trade)

Deleting a Strategy

Will DELETE (CASCADE):

  • All strategy rules
  • All playbook-strategy associations
  • All chart book-strategy associations
  • All write-up-strategy associations
  • All tag associations

Will SET NULL:

  • Trade group references to this strategy
  • Execution references to this strategy
  • Chart book references to this strategy

Deleting a Playbook

Will DELETE (CASCADE):

  • Playbook criteria
  • Playbook-strategy associations
  • Tag associations
  • Trading plan-playbook associations
  • Trade writeup-playbook associations

Will SET NULL:

  • Trade group playbook references
  • Chart book playbook references

Deleting a Tag

Will DELETE (CASCADE):

  • All associations of this tag (across trades, write-ups, plans, strategies, etc.)

✅ LOW RISK Operations

These operations have minimal cascade effects.

Deleting a Trading Plan

Will DELETE (CASCADE):

  • Trading plan-playbook associations
  • Tag associations

Deleting a Trade Write-up

Will DELETE (CASCADE):

  • Trade writeup-playbook associations
  • Trade writeup-strategy associations
  • Tag associations

Deleting a Report Card

Will DELETE (CASCADE):

  • Tag associations

Deleting a Chart Book

Will DELETE (CASCADE):

  • Chart book-strategy associations
  • Tag associations

Deleting a Payout

Will UPDATE:

  • Account payout totals will be recalculated
  • Account balance will be adjusted

Deleting a Document

Will DELETE:

  • Associated file from storage

The API will warn you if the file was removed from storage. If file deletion fails, the document record is still deleted.


Complete CASCADE Relationships Table

ResourceCASCADE DeletesSET NULL ActionsRisk
Accounttrades, executions, payouts, documents, tag associations-🚨 HIGH
Tag Grouptags, all tag associations-🚨 HIGH
Tradeexecutions, write-ups, tag associations-⚠️ Medium
Strategystrategy_rules, playbook links, chart book links, writeup links, tag associationstrade.strategy_id, execution.strategy_id⚠️ Medium
Playbookcriteria, strategy links, tag associations, trading plan links, writeup linkstrade.playbook_id, chart_book.playbook_id⚠️ Medium
Tagall tag associations-⚠️ Medium
Trading Planplaybook links, tag associations-✅ Low
Trade Write-upplaybook links, strategy links, tag associations-✅ Low
Report Cardtag associations-✅ Low
Chart Bookstrategy links, tag associations-✅ Low
Payout-(recalculates account totals)✅ Low
Documentstorage file-✅ Low

Best Practices

Before Deleting

  1. Query the resource first to understand what's linked
  2. Read the cascade warnings in the API response
  3. Back up critical data if deleting high-risk resources
  4. Test with non-critical data first before deleting important records
  5. Consider alternatives like archiving instead of deleting

For High-Risk Operations

# BEFORE deleting an account, check what will be affected
curl -X GET "https://app.mypropjournal.com/api/v1/accounts/ACCOUNT_ID" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Review: trade count, payout count, document count

# Export data if needed
curl -X GET "https://app.mypropjournal.com/api/v1/trades?account_id=ACCOUNT_ID&limit=1000" \
  -H "Authorization: Bearer YOUR_API_KEY" > trades_backup.json

Implementing in Your Application

Always log cascade impacts for audit purposes:

async function deleteResource(endpoint, id) {
  try {
    const response = await fetch(
      `https://app.mypropjournal.com/api/v1/${endpoint}/${id}`,
      {
        method: 'DELETE',
        headers: { Authorization: `Bearer ${apiKey}` }
      }
    );
    
    const result = await response.json();
    
    if (result.success) {
      // Log cascade impact
      if (result.warnings && result.warnings.length > 0) {
        console.warn('CASCADE DELETE IMPACT:', {
          resource: endpoint,
          id,
          warnings: result.warnings,
          timestamp: new Date().toISOString()
        });
        
        // Notify user
        if (result.warnings.length > 5) {
          alert(`Warning: This deletion affected ${result.warnings.length} related items.`);
        }
      }
      
      return result;
    } else {
      throw new Error(result.error?.message || 'Delete failed');
    }
  } catch (error) {
    console.error('Deletion failed:', error);
    throw error;
  }
}

Safety Checklist

Before performing DELETE operations with important data:

  • ✓ I have reviewed what will be deleted
  • ✓ I understand that deletions are permanent
  • ✓ I have backed up critical data (if applicable)
  • ✓ I have tested this operation with non-critical data first
  • ✓ I have implemented error handling for warnings
  • ✓ My application logs cascade impacts for audit

Common Scenarios

Scenario 1: Cleaning Up Old Data

Goal: Remove old demo trades without affecting real data

# Step 1: Query for demo trades
curl -X GET "https://app.mypropjournal.com/api/v1/trades?tags=demo&limit=100" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Step 2: Delete each trade (warnings will show executions deleted)
curl -X DELETE "https://app.mypropjournal.com/api/v1/trades/TRADE_ID" \
  -H "Authorization: Bearer YOUR_API_KEY"

Scenario 2: Reorganizing Strategies

Goal: Delete old strategy and update references

# Step 1: Check what uses this strategy
curl -X GET "https://app.mypropjournal.com/api/v1/strategies/STRATEGY_ID" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Step 2: Update trades to use new strategy (optional)
curl -X PUT "https://app.mypropjournal.com/api/v1/trades/TRADE_ID" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"strategy_id": "NEW_STRATEGY_ID"}'

# Step 3: Delete old strategy (SET NULL will unlink remaining references)
curl -X DELETE "https://app.mypropjournal.com/api/v1/strategies/STRATEGY_ID" \
  -H "Authorization: Bearer YOUR_API_KEY"

Scenario 3: Archiving Instead of Deleting

For accounts, use the archive filter to hide inactive accounts without deleting data:

# List only active accounts
curl -X GET "https://app.mypropjournal.com/api/v1/accounts?archived=active" \
  -H "Authorization: Bearer YOUR_API_KEY"

Error Recovery

If You Accidentally Delete Data

There is NO undo for DELETE operations. Data is permanently removed and cannot be recovered.

Prevention is key:

  1. Always test deletions with non-critical data first
  2. Export/backup before bulk deletions
  3. Use archiving features when available
  4. Implement confirmation dialogs in your UI
  5. Require elevated permissions for high-risk deletes


Questions? If you need clarification on CASCADE behavior for a specific resource, consult the individual endpoint documentation or contact support.