feat(controls): atom-inheritance schema-aware (text + jsonb source_citation)
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-consent (push) Successful in 36s
CI / test-python-voice (push) Successful in 40s
CI / test-bqas (push) Successful in 38s

Prod canonical_controls.source_citation ist text-mit-JSON (DB-Swap-Anomalie),
macmini ist jsonb. _art()-Helper nutzt pg_input_is_valid(col::text,'jsonb') +
(col::text)::jsonb->>'article' (PG16+) -> ein Skript fuer beide Schemata.
Prod-Apply 2026-06-21 verifiziert: Zitierfaehigkeit 6,8%->60,8% (+169.755),
Stichprobe 8/8 korrekt. macmini-Dry-Run 0 (idempotent, kein Regress).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-06-21 22:44:38 +02:00
parent 0c5f1fd7a4
commit f398088fbb
@@ -33,18 +33,21 @@ import sys
DB_URL = os.getenv("DATABASE_URL", "postgresql://breakpilot:breakpilot@localhost:5432/breakpilot_db") DB_URL = os.getenv("DATABASE_URL", "postgresql://breakpilot:breakpilot@localhost:5432/breakpilot_db")
def _art(alias: str) -> str:
"""SQL for source_citation->>'article' that works whether the column is jsonb
(macmini) or text-containing-JSON (prod schema anomaly from the DB swap).
pg_input_is_valid (PG16+) guards rows with invalid JSON so the cast never errors."""
col = f"{alias}.source_citation"
return (
f"(CASE WHEN {col} IS NOT NULL AND pg_input_is_valid({col}::text, 'jsonb') "
f"THEN ({col}::text)::jsonb->>'article' ELSE NULL END)"
)
# A row "needs" a citation when it has no article yet. # A row "needs" a citation when it has no article yet.
_NEEDS = ( _NEEDS = f"({_art('cc')} IS NULL OR {_art('cc')} = '')"
"(cc.source_citation IS NULL "
" OR cc.source_citation->>'article' IS NULL "
" OR cc.source_citation->>'article' = '')"
)
# A parent can supply one when it carries a real article. # A parent can supply one when it carries a real article.
_PARENT_HAS = ( _PARENT_HAS = f"({_art('p')} IS NOT NULL AND {_art('p')} <> '')"
"p.source_citation IS NOT NULL "
"AND p.source_citation->>'article' IS NOT NULL "
"AND p.source_citation->>'article' <> ''"
)
SQL_REPORT = f""" SQL_REPORT = f"""
SET search_path TO compliance, public; SET search_path TO compliance, public;