Stage 5: Alembic migrations, durable call rows, one transcript truth
Alembic replaces create_all as the schema authority: async env.py against Base.metadata (CLI and in-app entry paths share it via config.attributes["connection"]), an autogenerated baseline of the create_all-era schema, and init_db now runs upgrade head — stamping the baseline first on a pre-Alembic database so existing deployments adopt cleanly. create_all remains for tests only. Calls are durable from the start: CallManager gains an on_call_created hook (wired to persist_call_on_create) that inserts an in_progress CallRecord the moment a call is created; persist_call_on_end finalizes that same row. A SIGKILL mid-call now leaves an in_progress row instead of erasing the call from history (verified live against the dev database). One transcript representation: ActiveCall.transcript_chunks holds TranscriptEntry (t_offset_ms, speaker, text) — add_transcript stamps real offsets from connect time, receptionist passes speaker instead of encoding it into "caller: ..." strings, persisted chunks carry real seek offsets, and the dead CallRecord.transcript Text column is dropped by migration. Device.is_online migrates String → Boolean (with a USING cast for existing rows). Model de-triplication: CallResponse/CallStatusResponse build via from_call classmethods (one ActiveCall→response mapping); DeviceStatus deleted — can_receive_call is a computed field on Device and the list endpoint returns the domain model; all row↔dict and row↔domain mapping now lives in call_persistence.py (record_summary/record_detail/chunk_to_dict + device row functions). New tests/test_data_layer.py: upgrade-head-matches-models, pre-Alembic adoption, durable in_progress rows, end-without-create fallback, transcript offsets, consolidated response models. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
30
api/calls.py
30
api/calls.py
@@ -40,12 +40,7 @@ async def make_call(
|
||||
call_flow_id=request.call_flow_id,
|
||||
services=request.services,
|
||||
)
|
||||
return CallResponse(
|
||||
call_id=call.id,
|
||||
status=call.status.value,
|
||||
number=request.number,
|
||||
mode=request.mode.value,
|
||||
)
|
||||
return CallResponse.from_call(call)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except Exception as e:
|
||||
@@ -81,11 +76,8 @@ async def hold_slayer(
|
||||
call_flow_id=request.call_flow_id,
|
||||
device=request.transfer_to,
|
||||
)
|
||||
return CallResponse(
|
||||
call_id=call.id,
|
||||
status="navigating_ivr",
|
||||
number=request.number,
|
||||
mode="hold_slayer",
|
||||
return CallResponse.from_call(
|
||||
call,
|
||||
message="Hold Slayer activated. I'll ring you when a human picks up. ☕",
|
||||
)
|
||||
except ValueError as e:
|
||||
@@ -113,21 +105,7 @@ async def get_call(
|
||||
if not call:
|
||||
raise HTTPException(status_code=404, detail=f"Call {call_id} not found")
|
||||
|
||||
return CallStatusResponse(
|
||||
call_id=call.id,
|
||||
status=call.status.value,
|
||||
direction=call.direction,
|
||||
remote_number=call.remote_number,
|
||||
mode=call.mode.value,
|
||||
duration=call.duration,
|
||||
hold_time=call.hold_time,
|
||||
audio_type=call.current_classification.value,
|
||||
intent=call.intent,
|
||||
transcript_excerpt=call.transcript[-500:] if call.transcript else None,
|
||||
classification_history=call.classification_history[-50:],
|
||||
current_step=call.current_step_id,
|
||||
services=call.services,
|
||||
)
|
||||
return CallStatusResponse.from_call(call)
|
||||
|
||||
|
||||
@router.post("/{call_id}/transfer")
|
||||
|
||||
Reference in New Issue
Block a user