Skip to content

betting_combat.schemas.tables.base

base.py — what every table shares: where it lives, its two stamps, and the two verbs between the contract it stores and its row.

SCHEMA the Postgres schema of the rebuilt tables: ufc (database betting), beside
today's betting_combat until the switch
Stored a table's base: its contract (``CONTRACT``), its columns in order, and
``row`` (a contract → the row a write lands) · ``fact`` (a read row → the
contract)
choice · present · maybe · vendor_key · vendor_keys the checks and indexes tables repeat

created_at and updated_at are the row’s, never the fact’s: the database stamps them (created_at on insert; updated_at by the table’s trigger, only when an upsert really changes the row, as common-db’s upsert leaves unchanged rows untouched).

Classes

Stored

Bases: Base

A table the package writes: its contract, its columns, and the verbs between them.

columns

columns() -> tuple[str, ...]

The table’s columns, in its order.

fact

fact(row: Mapping[str, Any]) -> BaseModel

The contract a read row holds (its stamps, and any column it lacks a field for, aside).

row

row(fact: BaseModel) -> dict[str, Any]

The row a write lands for fact: every written column, in order. Enums land as their values, tuples as array literals (pg_array), mappings as JSON text.

touch_ddl

touch_ddl() -> list[str]

The statements that move updated_at when a row really changes (common-db’s ensure makes the table; this, after it, the trigger). Idempotent.

written

written() -> tuple[str, ...]

The columns a write hands over: every one but the table’s own (OWN).

Functions

choice

choice(table: str, column: str, values: type[StrEnum], nullable: bool = True) -> CheckConstraint

The column holds one of the enum’s values (or NULL).

maybe

maybe(table: str, column: str) -> CheckConstraint

A text column that is NULL or not blank.

pg_array

pg_array(values: tuple[Any, ...]) -> str

An array as Postgres’ literal, ’{“a”,“b”}’: common-db’s COPY carries no list columns, and the server parses the literal into the column’s array type (text[], float8[]; a read hands a list).

present

present(table: str, column: str) -> CheckConstraint

A text column that is never blank.

vendor_key

vendor_key(table: str, column: str) -> Index

A vendor’s id: one of ours per value, where the vendor has one.

vendor_keys

vendor_keys(table: str, column: str) -> Index

A vendor’s ids where it has several for one of ours: searched with = ANY. A value on two rows cannot be refused by an index on an array; the normaliser’s check refuses it.