Skip to content

karenina.storage.generated_models

generated_models

Auto-generated SQLAlchemy models from Pydantic schemas.

This module uses the PydanticSQLAlchemyMapper to automatically generate the VerificationResultModel from the VerificationResult Pydantic class. This eliminates manual column definition and ensures the schema stays in sync with the domain model.

Classes

Functions

get_column_names

get_column_names() -> list[str]

Get all column names from the generated model.

Useful for debugging and introspection.

Source code in src/karenina/storage/generated_models.py
def get_column_names() -> list[str]:
    """Get all column names from the generated model.

    Useful for debugging and introspection.
    """
    if hasattr(VerificationResultModel, "__table__"):
        return [c.name for c in VerificationResultModel.__table__.columns]
    return []

get_indexed_columns

get_indexed_columns() -> list[str]

Get column names that have individual indexes.

Useful for debugging and introspection.

Source code in src/karenina/storage/generated_models.py
def get_indexed_columns() -> list[str]:
    """Get column names that have individual indexes.

    Useful for debugging and introspection.
    """
    if hasattr(VerificationResultModel, "__table__"):
        indexed = []
        for c in VerificationResultModel.__table__.columns:
            if c.index:
                indexed.append(c.name)
        return indexed
    return []

print_schema_info

print_schema_info() -> None

Print schema information for debugging.

Shows all columns, their types, and indexes.

Source code in src/karenina/storage/generated_models.py
def print_schema_info() -> None:
    """Print schema information for debugging.

    Shows all columns, their types, and indexes.
    """
    if not hasattr(VerificationResultModel, "__table__"):
        logger.info("Model has no __table__ attribute")
        return

    table = VerificationResultModel.__table__
    logger.info("Table: %s", table.name)
    logger.info("Columns (%d):", len(table.columns))

    for col in table.columns:
        index_marker = " [INDEXED]" if col.index else ""
        nullable = "NULL" if col.nullable else "NOT NULL"
        logger.info("  %s: %s %s%s", col.name, col.type, nullable, index_marker)

    logger.info("Indexes (%d):", len(table.indexes))
    for idx in table.indexes:
        cols = ", ".join(c.name for c in idx.columns)
        logger.info("  %s: (%s)", idx.name, cols)