app.repository.strategy_definition_repository module¶
Repository for StrategyDefinition.
Encapsulates the versioning queries the service relies on: max-version lookup, status transitions, and tenant-scoped reads. Heavier business logic (forking drafts on update, archiving published siblings on publish) is intentionally left to the service so this layer stays a thin SQL adapter.
- class app.repository.strategy_definition_repository.StrategyDefinitionRepository(session_factory, model=<class 'app.model.strategy_definition.StrategyDefinition'>)[source]¶
Bases:
BaseRepositoryAsync repository for the
strategydefinitiontable.- Parameters:
session_factory (Callable[[...], AbstractAsyncContextManager[AsyncSession]])
- async list_for_realm(*, realmId, status=None, type=None, limit=100)[source]¶
List rows visible to a tenant, most recent first.
realmId=Noneis treated as “global”; callers that want every row across realms must pass it explicitly via a separate admin helper (not implemented yet - tenancy stays strict).- Parameters:
realmId (str | None)
status (str | None)
type (str | None)
limit (int)
- Return type:
List[StrategyDefinition]
- async get_for_realm(*, id, realmId)[source]¶
Fetch one row scoped by id + tenant. Returns
Nonewhen the row belongs to another tenant; the service maps that to a 404 so we don’t leak existence across realms.- Parameters:
id (str)
realmId (str | None)
- Return type:
StrategyDefinition | None
- async list_versions(*, realmId, name)[source]¶
Return every row in a
(realmId, name)family, newest version first. Used by the history endpoint and already useful from the service when looking for the latest draft or published sibling.- Parameters:
realmId (str | None)
name (str)
- Return type:
List[StrategyDefinition]
- async get_max_version(*, realmId, name)[source]¶
Highest version number for a
(realmId, name)family, or 0 if the family does not exist yet. The service uses this to allocate the next draft version atomically.- Parameters:
realmId (str | None)
name (str)
- Return type:
int
- async get_published(*, realmId, name)[source]¶
Return the currently published row of a family, or
None.- Parameters:
realmId (str | None)
name (str)
- Return type:
StrategyDefinition | None
- async get_version(*, realmId, name, version)[source]¶
Fetch a specific
(realmId, name, version)row.Used by the rollback flow to locate the target version being promoted back to PUBLISHED. Returns
Nonewhen the version does not exist in the family; the service maps that to a 404 so we don’t leak cross-family info.- Parameters:
realmId (str | None)
name (str)
version (int)
- Return type:
StrategyDefinition | None