acupedia-api/app/bootstrap/seed_content/schema.py

29 lines
789 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:
"""
Validate and return the schema used by content/media seeders.
Production/default ownership is ``content``. The explicit override is
retained for isolated tests or temporary development schemas, preserving
the existing seeder constructor capability without accepting arbitrary SQL.
"""
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",
]