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
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.
51 lines
2.0 KiB
Python
51 lines
2.0 KiB
Python
"""Premium credit ledger: the SKUs a standard credit never pays for.
|
|
|
|
Two kinds, each its own append-only balance (``SUM(delta)`` per user and kind):
|
|
|
|
* ``premium_voice`` - 1 credit = one reel narrated with a premium (ElevenLabs)
|
|
voice; premium dubbing spends several.
|
|
* ``ai_video`` - 1 credit = 1 US cent of AI-video / AI-presenter value,
|
|
spent at 3x the measured provider cost.
|
|
|
|
Kept apart from ``credit_ledger`` so the standard reel balance (and every
|
|
query that sums it) is untouched. Imported by :mod:`app.models.db.models` so
|
|
the table registers on the shared metadata.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import BigInteger, DateTime, ForeignKey, Index, Integer, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.db.base import Base
|
|
|
|
KIND_PREMIUM_VOICE: str = "premium_voice"
|
|
KIND_AI_VIDEO: str = "ai_video"
|
|
KINDS: tuple[str, ...] = (KIND_PREMIUM_VOICE, KIND_AI_VIDEO)
|
|
|
|
|
|
class PremiumCreditLedger(Base):
|
|
"""Append-only premium credit ledger (one row per grant or debit)."""
|
|
|
|
__tablename__ = "premium_credit_ledger"
|
|
|
|
id: Mapped[int] = mapped_column(
|
|
BigInteger().with_variant(Integer, "sqlite"), primary_key=True, autoincrement=True
|
|
)
|
|
user_id: Mapped[str] = mapped_column(ForeignKey("users.id"), index=True, nullable=False)
|
|
# premium_voice | ai_video
|
|
kind: Mapped[str] = mapped_column(String(20), nullable=False)
|
|
delta: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
# purchase:<provider>:<ref> | premium_debit:<job> | premium_refund:<job> | ...
|
|
reason: Mapped[str] = mapped_column(String(80), nullable=False)
|
|
job_id: Mapped[str | None] = mapped_column(String(32), index=True, nullable=True)
|
|
balance_after: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
__table_args__ = (Index("ix_premium_credit_ledger_user_kind", "user_id", "kind"),)
|
|
|
|
|
|
__all__ = ["KINDS", "KIND_AI_VIDEO", "KIND_PREMIUM_VOICE", "PremiumCreditLedger"]
|