trader.persistence.deployed_versions module

Repository for deployed_versions (issue #30).

A sparse deploy-event log, not a per-invocation timestamp — see DeployedVersion’s docstring for why. record_if_changed is the only write; latest/version_at are the two reads a future consumer (tools/ roi_investigation.py, trader/replay/) would use to attribute a historical row to the code that produced it.

class trader.persistence.deployed_versions.DeployedVersionRepository(session_factory)[source]

Bases: object

Writes and reads deployed_versions.

Parameters:

session_factory (sessionmaker[Session])

latest()[source]

The most recently detected version, or None if never recorded.

Return type:

DeployedVersion | None

record_if_changed(git_sha, git_ref, *, now)[source]

Insert a new row iff git_sha differs from the most recent one.

Returns whether it inserted. A process running unchanged code across many cycles or invocations must not grow this table on every one of them — only an actual version change is an event worth recording.

Parameters:
  • git_sha (str)

  • git_ref (str | None)

  • now (datetime)

Return type:

bool

version_at(instant)[source]

The version in effect at instant, or None if unrecorded.

The row with the greatest detected_at <= instantNone when instant predates every recorded version, which must read as unknown rather than defaulting to the earliest row on file.

Parameters:

instant (datetime)

Return type:

DeployedVersion | None