fix(profiles): delete a profile's generations instead of orphaning them

This commit is contained in:
SEPURI-SAI-KRISHNA
2026-10-04 00:19:41 +00:00
committed by capy-ai-staging[bot]
parent 4f54e16824
commit 4750b47b04
4 changed files with 243 additions and 11 deletions
+25 -1
View File
@@ -11,7 +11,14 @@ from sqlalchemy import func
from sqlalchemy.orm import Session
from .. import config
from ..database import Generation as DBGeneration, ProfileSample as DBProfileSample, VoiceProfile as DBVoiceProfile
from ..database import (
CaptureSettings as DBCaptureSettings,
Generation as DBGeneration,
MCPClientBinding as DBMCPClientBinding,
ProfileChannelMapping as DBProfileChannelMapping,
ProfileSample as DBProfileSample,
VoiceProfile as DBVoiceProfile,
)
from ..models import (
EffectConfig,
ProfileSampleResponse,
@@ -21,6 +28,7 @@ from ..models import (
from ..utils.audio import save_audio, validate_and_load_reference_audio
from ..utils.cache import _get_cache_dir, clear_profile_cache
from ..utils.images import process_avatar, validate_image
from . import history
logger = logging.getLogger(__name__)
@@ -429,7 +437,23 @@ async def delete_profile(
if not profile:
return False
# Generations carry a non-null FK to the profile and the history query
# inner-joins profiles, so anything left behind here becomes a row the UI
# can never show and a .wav in data/generations the user can never reclaim.
deleted_generations = await history.delete_generations_by_profile(profile_id, db)
if deleted_generations:
logger.info("Deleted %d generations belonging to profile %s", deleted_generations, profile_id)
db.query(DBProfileSample).filter_by(profile_id=profile_id).delete()
db.query(DBProfileChannelMapping).filter_by(profile_id=profile_id).delete()
# Nullable pointers at the profile — resolve_profile() already tolerates a
# dangling id, but leaving one behind makes the UI show an empty selection
# that the user can't clear.
db.query(DBMCPClientBinding).filter_by(profile_id=profile_id).update({"profile_id": None})
db.query(DBCaptureSettings).filter_by(default_playback_voice_id=profile_id).update(
{"default_playback_voice_id": None}
)
db.delete(profile)
db.commit()