refactor(dolt): pass run_id to SourceImporter.promote

Both real target tables (fundamental_snapshots, earnings_events) carry an
import_run_id; stamping requires the current run's id. A2 (the earnings
importer) is the first real consumer, so promote gains a run_id argument rather
than having importers hack the running row out of the framework. Protocol +
call site updated; the A1 fake importer now stamps and asserts import_run_id.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 10:55:11 +02:00
co-authored by Claude Opus 4.8
parent 1b821e1a1e
commit e5a62ca648
2 changed files with 16 additions and 6 deletions
+5 -3
View File
@@ -94,9 +94,11 @@ class SourceImporter(Protocol):
"""Run the source's validation gates against ``staged``. Read-only."""
...
async def promote(self, db: AsyncSession, staged: Any) -> dict[str, int]:
async def promote(self, db: AsyncSession, staged: Any, run_id: int) -> dict[str, int]:
"""Apply ``staged`` to the live tables. Called inside the promotion
transaction; the caller commits. Returns row-count deltas."""
transaction; the caller commits. ``run_id`` is the current
``data_import_runs.id`` so written rows can be stamped with their
``import_run_id``. Returns row-count deltas."""
...
@@ -213,7 +215,7 @@ async def run_import(
return run
# Promotion: importer writes + run-row flip in one transaction.
row_counts = await importer.promote(session, staged)
row_counts = await importer.promote(session, staged, run.id)
run.status = STATUS_PROMOTED
run.row_counts_json = json.dumps(row_counts, default=str)
run.completed_at = _now()