33 lines
963 B
Python
33 lines
963 B
Python
"""Add cascade delete logic for product deletion"""
|
|
import sys, json
|
|
sys.path.insert(0, '.')
|
|
from services.db import query
|
|
|
|
# Check tables
|
|
tables = ['bom', 'planning_prediction', 'daily_forecast']
|
|
results = {}
|
|
for t in tables:
|
|
try:
|
|
cols = query(f"SHOW COLUMNS FROM {t}")
|
|
results[t] = [c['Field'] for c in cols]
|
|
except Exception as e:
|
|
results[t] = f"ERROR: {e}"
|
|
|
|
# Load current products.py and find the delete route
|
|
with open('routes/products.py') as f:
|
|
content = f.read()
|
|
|
|
# Find product_delete function
|
|
idx = content.find('def product_delete()')
|
|
end_idx = content.find('\n@products_bp.route', idx)
|
|
if end_idx == -1:
|
|
end_idx = len(content)
|
|
delete_func = content[idx:end_idx]
|
|
|
|
results['delete_route_location'] = idx
|
|
results['delete_func'] = delete_func[:200]
|
|
|
|
with open('/tmp/fix_cascade_result.json', 'w') as f:
|
|
json.dump(results, f, ensure_ascii=False, indent=2)
|
|
print(f"Done. Found delete route at position {idx}")
|