videogen/apps/api/app/models/db/character_refs.py
caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

63 lines
2.5 KiB
Python

"""Character reference-image persistence (Wave 4 — identity lock).
A :class:`CharacterReference` binds one OWNED ``uploads/`` object (a face / body
/ outfit / pose still, or a full character sheet) to a saved
:class:`~app.models.db.characters.Character`. The bound references are the
IP-Adapter / LoRA conditioning inputs that keep a recurring AI character visually
identical across shots, and their sorted digest folds into the character's
``identity_key`` (drift/dupe detection).
Only an owned upload key is ever stored here (ownership validated at the domain
boundary via ``media.service.require_owned_asset``) — never a new upload path and
never a raw client URL (SSRF §8). Registered on ``Base.metadata`` via
``migrations/env.py`` like ``media_jobs``. Nullability follows the repo rule.
"""
from __future__ import annotations
import uuid
from datetime import datetime
from sqlalchemy import DateTime, ForeignKey, Integer, String, func, text
from sqlalchemy.orm import Mapped, mapped_column
from app.models.db.base import Base
def _uuid() -> str:
return uuid.uuid4().hex
class CharacterReference(Base):
"""One owned reference image bound to a character for identity conditioning."""
__tablename__ = "character_references"
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_uuid)
character_id: Mapped[str] = mapped_column(
ForeignKey("characters.id"), index=True, nullable=False
)
user_id: Mapped[str] = mapped_column(
ForeignKey("users.id"), index=True, nullable=False
)
# The OWNED ``uploads/`` R2 key (ownership checked before insert).
r2_key: Mapped[str] = mapped_column(String(512), nullable=False)
# face | body | outfit | pose | sheet
role: Mapped[str] = mapped_column(
String(16), default="sheet", server_default=text("'sheet'"), nullable=False
)
content_type: Mapped[str] = mapped_column(
String(80), default="", server_default=text("''"), nullable=False
)
width: Mapped[int] = mapped_column(
Integer, default=0, server_default=text("0"), nullable=False
)
height: Mapped[int] = mapped_column(
Integer, default=0, server_default=text("0"), nullable=False
)
# Optional precomputed identity-embedding object key (nullable — filled later).
embedding_key: Mapped[str | None] = mapped_column(String(512), nullable=True)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), index=True, nullable=False
)