26 lines
741 B
Python
26 lines
741 B
Python
from __future__ import annotations
|
|
|
|
import re
|
|
|
|
from app.db.schemas import CONTENT_SCHEMA
|
|
|
|
|
|
_SCHEMA_IDENTIFIER_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
|
|
|
|
|
|
def resolve_content_schema(schema: str = CONTENT_SCHEMA) -> str:
|
|
"""
|
|
Return a validated PostgreSQL schema identifier for content/search raw SQL.
|
|
|
|
Production ownership is ``content``. The optional override is retained only
|
|
to preserve the repository constructor contract for isolated tests and
|
|
development schemas.
|
|
"""
|
|
candidate = schema.strip()
|
|
if not _SCHEMA_IDENTIFIER_RE.fullmatch(candidate):
|
|
raise ValueError(f"Invalid PostgreSQL schema identifier: {schema!r}")
|
|
return candidate
|
|
|
|
|
|
__all__ = ["CONTENT_SCHEMA", "resolve_content_schema"]
|