Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions polylogue/storage/sqlite/archive_tiers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
PolylogueStrEnum,
nullable_sql_check_in,
sql_check_in,
sql_string_literal,
)


Expand All @@ -14,6 +15,29 @@ def check(column: str, enum_type: type[PolylogueStrEnum]) -> str:
return sql_check_in(column, enum_type)


def literal_check(column: str, *values: str) -> str:
"""Return a non-null ``column IN (...)`` expression for explicit literals.

Mirrors :func:`check`, but for closed vocabularies expressed as
``typing.Literal`` aliases rather than ``PolylogueStrEnum`` types. Callers
expand the alias with ``typing.get_args`` at the call site so this helper
stays free of an ``insights`` import inside the storage substrate.

Restored: PR #3458 deleted this as an "uncalled generator", but
``archive_tiers/index.py``'s ``delegation_facts`` DDL calls it twice
(``mapping_state``, ``result_status`` CHECK clauses) -- the deletion
broke the import chain for the whole ``archive_tiers`` package (and
therefore ``ArchiveStore``, the CLI, and every test) on ``master`` as of
5798b3dd1. The "zero call sites" audit was simply wrong; both call
sites are plain ``literal_check(...)`` calls, not aliased or generated.
Re-verify with a real grep before deleting again.
"""
if not values:
raise ValueError("literal_check requires at least one value")
rendered = ", ".join(sql_string_literal(value) for value in values)
return f"{column} IN ({rendered})"


def nullable_check(column: str, enum_type: type[PolylogueStrEnum]) -> str:
"""Return a nullable enum CHECK expression."""
return nullable_sql_check_in(column, enum_type)
Expand Down Expand Up @@ -89,6 +113,7 @@ def json_array_check(column: str, *, nullable: bool = False) -> str:
"json_array_check",
"json_check",
"json_object_check",
"literal_check",
"nullable_check",
"order_check",
]