cadrumo.adapters.persistence.storage.sql.orm module

Internal SQLAlchemy ORM mapper classes.

Declares the schema materialised by the storage engine. Intentionally kept out of the adapters.persistence.storage public API: repositories bridge between these rows and their typed records.

class Base(**kwargs)[source]

Bases: DeclarativeBase

Declarative base for every ORM mapper class in this package.

Parameters:

kwargs (Any)

metadata: ClassVar[MetaData]

Refers to the _schema.MetaData collection that will be used for new _schema.Table objects.

registry: ClassVar[_RegistryType]

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

class TransactionDateIndexRow(**kwargs)[source]

Bases: Base

Plaintext routing row: one ledger transaction’s filing date and year.

This table is a derived, rebuildable read-side cache co-written atomically with SecureObjectRow ledger writes (see TransactionCatalogueRepository). It exists purely to let a period-scoped ledger read select the candidate transaction ids for a date range with a plaintext SQL predicate, so only those rows need to be decrypted – never the whole per-bucket catalogue.

The row carries ONLY non-sensitive routing keys: the bucket id, the transaction id, its filing date (value_date or booked_date – the same field every ledger aggregator already filters on), the filing year the date falls in, and the inclusive span of every date the row can file an observation under. No amount, counterparty, description, NIF, or other financial content may ever be added to this table; it is plaintext by design (SensitivityClass CACHE) and correctness never depends on it being present or fresh – a missing or incomplete index falls back to the full encrypted scan.

Variables:
  • id – Surrogate integer primary key.

  • bucket_id – Owning profile bucket, so a shared database never mixes two buckets’ routing rows.

  • transaction_id – The ledger transaction’s stable content-derived id.

  • filing_date – value_date or booked_date (whichever the ledger aggregation layer would use) as a plain SQL Date.

  • filing_year – filing_date.year, indexed separately so a year-scoped candidate-id query does not need a date-range predicate at all.

  • eligible_from – Earliest date this row can file an observation under, per transaction_eligible_date_span(). Equal to filing_date unless an IVA criterio-de-caja timing override moves the row’s devengo or collection dates off it.

  • eligible_to – Latest such date, inclusive. A period-scoped partition selects on span OVERLAP rather than on filing_date, so a row booked in one quarter that carries a prior-quarter cash-accounting devengo is never dropped from the candidate set.

id: Mapped[_intpk]
bucket_id: Mapped[_str64]
transaction_id: Mapped[_str64]
filing_date: Mapped[_date_required]
filing_year: Mapped[_int_required]
eligible_from: Mapped[_date_required]
eligible_to: Mapped[_date_required]
class SecureObjectRow(**kwargs)[source]

Bases: Base

Encrypted byte-object row for sensitive application payloads.

Domain repositories use this table for financial catalogues and workflow state that must not land as standalone JSON files. The payload column is a SQL BLOB holding the AEAD wire bytes; the repository encrypts and decrypts it explicitly (rather than through a column TypeDecorator) so the row identity (namespace + object_key digest + schema_version) can be bound into the AEAD associated data, making a ciphertext refuse to decrypt under any other row. The remaining fields are routing, revision-lineage, and integrity metadata.

id: Mapped[_intpk]
namespace: Mapped[_str128]
object_key: Mapped[_hashed_lookup]
classification: Mapped[_str32]
schema_version: Mapped[_int_required]
written_at: Mapped[_datetime_tz]
revision_id: Mapped[_str64_opt]
previous_revision_id: Mapped[_str64_opt]
revision_ancestor_ids: Mapped[_text_opt]
previous_payload_hash: Mapped[_str64_opt]
payload_hash: Mapped[_str64_opt]
ciphertext_hash: Mapped[_str64_opt]
revision_written_at: Mapped[_datetime_tz_opt]
write_provenance: Mapped[_str255_opt]
source_event_id: Mapped[_str128_opt]
conflict_policy: Mapped[_str32_opt]
payload: Mapped[_large_binary]
metadata

Alembic target_metadata for autogenerate.