Skip to content

Commit e342c59

Browse files
committed
feat: add schema association check before deleting pathogen
1 parent 2cda3c3 commit e342c59

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,20 @@ def delete(self, pathogen_id):
341341

342342
with get_db_cursor() as cursor:
343343
if hard_delete:
344+
345+
# Check if there are associated schemas
346+
cursor.execute("""
347+
SELECT COUNT(*) as count FROM schemas
348+
WHERE pathogen_id = %s
349+
""", (pathogen_id,))
350+
351+
schema_count = cursor.fetchone()['count']
352+
353+
if schema_count > 0:
354+
return {
355+
'error': f'Cannot delete pathogen: {schema_count} schema(s) are still associated with it. Delete schemas first or use soft delete.'
356+
}, 400
357+
344358
# Hard delete - permanently remove from database
345359
cursor.execute("""
346360
DELETE FROM pathogens

0 commit comments

Comments
 (0)