修复冻结积分BUG | 拆镜状态异常BUG
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Float, ForeignKey, Index, Integer, String
|
||||
from sqlalchemy import Float, ForeignKey, Index, Integer, String, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base, TimestampMixin
|
||||
@@ -11,6 +11,13 @@ class CreditRecord(Base, TimestampMixin):
|
||||
# PostgreSQL/MySQL/SQLite 对 nullable unique 的处理都允许多条 NULL,兼容历史数据。
|
||||
Index("uq_credit_records_user_biz_key", "user_id", "biz_key", unique=True),
|
||||
Index("ix_credit_records_user_refund_for_biz_key", "user_id", "refund_for_biz_key"),
|
||||
Index(
|
||||
"uq_credit_records_user_refund_target",
|
||||
"user_id",
|
||||
"refund_for_biz_key",
|
||||
unique=True,
|
||||
postgresql_where=text("type = 'refund' AND refund_for_biz_key IS NOT NULL"),
|
||||
),
|
||||
Index("ix_credit_records_related_type", "related_id", "type"),
|
||||
Index("ix_credit_records_owner", "owner_type", "owner_id"),
|
||||
Index("ix_credit_records_subject_media", "credit_subject", "media_type"),
|
||||
|
||||
@@ -18,6 +18,7 @@ class GenerationRecord(Base, TimestampMixin, SoftDeleteMixin):
|
||||
)
|
||||
original_prompt: Mapped[str] = mapped_column(Text)
|
||||
optimized_prompt: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
prompt_usage_snapshot_json: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
gen_type: Mapped[str] = mapped_column(String(16), default="video")
|
||||
duration: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
aspect_ratio: Mapped[str | None] = mapped_column(String(8), nullable=True)
|
||||
@@ -95,6 +96,13 @@ class GenerationRecord(Base, TimestampMixin, SoftDeleteMixin):
|
||||
__table_args__ = (
|
||||
Index('idx_genrec_user_status_created', 'user_id', 'status', 'created_at'),
|
||||
Index('idx_genrec_project_status', 'project_id', 'status'),
|
||||
Index(
|
||||
'uq_genrec_user_idempotency_active',
|
||||
'user_id',
|
||||
'idempotency_key',
|
||||
unique=True,
|
||||
postgresql_where=text("idempotency_key IS NOT NULL AND deleted_at IS NULL"),
|
||||
),
|
||||
Index(
|
||||
'idx_genrec_next_poll_at',
|
||||
'next_poll_at',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import ForeignKey, Index, Integer, String
|
||||
from sqlalchemy import ForeignKey, Index, Integer, String, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base, TimestampMixin
|
||||
@@ -9,6 +9,13 @@ class TokenUsage(Base, TimestampMixin):
|
||||
__table_args__ = (
|
||||
Index("ix_token_usage_owner", "owner_type", "owner_id"),
|
||||
Index("ix_token_usage_biz_key", "biz_key"),
|
||||
Index(
|
||||
"uq_token_usage_user_biz_key",
|
||||
"user_id",
|
||||
"biz_key",
|
||||
unique=True,
|
||||
postgresql_where=text("biz_key IS NOT NULL"),
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(32), primary_key=True)
|
||||
|
||||
Reference in New Issue
Block a user