add Fabric read model rollback activation
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a053ff-1d6f-7fe2-ac1c-a6eb40a42a0c
This commit is contained in:
parent
cf40c7bb4e
commit
cdff3b7e08
5 changed files with 133 additions and 0 deletions
|
|
@ -221,6 +221,55 @@ async def ingest_fabric_graph_export(
|
|||
return import_run, True, False
|
||||
|
||||
|
||||
async def activate_fabric_graph_import(
|
||||
session: AsyncSession,
|
||||
import_id: Any,
|
||||
*,
|
||||
requested_by: str,
|
||||
) -> tuple[FabricGraphImport | None, Any | None, bool]:
|
||||
"""Select a retained valid import as the active read model.
|
||||
|
||||
Imports are immutable. Activation only moves the per-source ``is_latest``
|
||||
marker, which makes cutover rollback fast and avoids re-fetching an older
|
||||
authority payload during an incident.
|
||||
"""
|
||||
result = await session.execute(
|
||||
select(FabricGraphImport).where(FabricGraphImport.id == import_id)
|
||||
)
|
||||
import_run = result.scalar_one_or_none()
|
||||
if import_run is None:
|
||||
return None, None, False
|
||||
if import_run.validation_status != "valid":
|
||||
raise ValueError("Only a valid Fabric graph import can be activated.")
|
||||
|
||||
previous_result = await session.execute(
|
||||
select(FabricGraphImport).where(
|
||||
FabricGraphImport.source_repo_slug == import_run.source_repo_slug,
|
||||
FabricGraphImport.is_latest.is_(True),
|
||||
)
|
||||
)
|
||||
previous = previous_result.scalars().first()
|
||||
if previous is not None and previous.id == import_run.id:
|
||||
return import_run, previous.id, False
|
||||
|
||||
await _mark_latest(session, import_run)
|
||||
import_run.last_seen_at = datetime.now(timezone.utc)
|
||||
await _record_progress(
|
||||
session,
|
||||
"Fabric graph read model activation changed.",
|
||||
{
|
||||
"source_repo_slug": import_run.source_repo_slug,
|
||||
"import_id": str(import_run.id),
|
||||
"previous_import_id": str(previous.id) if previous else None,
|
||||
"content_hash": import_run.content_hash,
|
||||
"requested_by": requested_by,
|
||||
},
|
||||
)
|
||||
await session.commit()
|
||||
await session.refresh(import_run)
|
||||
return import_run, previous.id if previous else None, True
|
||||
|
||||
|
||||
def validate_fabric_graph_export(payload: dict[str, Any]) -> FabricGraphExportPayload:
|
||||
try:
|
||||
export = FabricGraphExportPayload.model_validate(payload)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue