实现虎牙充值商品列表与支付二维码

This commit is contained in:
yml2213
2026-07-04 23:48:53 +08:00
parent fa0d49ff8c
commit 5513b5a313
12 changed files with 1209 additions and 61 deletions
@@ -0,0 +1,77 @@
"""新增虎牙充值商品快照表
Revision ID: 20260704_0005
Revises: 20260704_0004
Create Date: 2026-07-04
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
revision: str = "20260704_0005"
down_revision: Union[str, None] = "20260704_0004"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def _has_table(bind, table_name: str) -> bool:
return sa.inspect(bind).has_table(table_name)
def _indexes(bind, table_name: str) -> set[str]:
if not _has_table(bind, table_name):
return set()
return {index["name"] for index in sa.inspect(bind).get_indexes(table_name)}
def _create_index_if_missing(bind, name: str, table_name: str, columns: list[str], unique: bool = False) -> None:
if name not in _indexes(bind, table_name):
op.create_index(name, table_name, columns, unique=unique)
def upgrade() -> None:
bind = op.get_bind()
if not _has_table(bind, "huya_recharge_goods_snapshot"):
op.create_table(
"huya_recharge_goods_snapshot",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("spu_id", sa.String(length=64), nullable=False),
sa.Column("sku_id", sa.String(length=64), nullable=True),
sa.Column("name", sa.String(length=256), nullable=True),
sa.Column("price", sa.Integer(), nullable=True),
sa.Column("stock", sa.Integer(), nullable=True),
sa.Column("buy_limit", sa.Integer(), nullable=True),
sa.Column("icon", sa.String(length=512), nullable=True),
sa.Column("description", sa.String(length=512), nullable=True),
sa.Column("task_id", sa.String(length=64), nullable=True),
sa.Column("task_name", sa.String(length=256), nullable=True),
sa.Column("raw", sa.JSON(), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
_create_index_if_missing(
bind,
"ix_huya_recharge_goods_snapshot_spu_id",
"huya_recharge_goods_snapshot",
["spu_id"],
)
_create_index_if_missing(
bind,
"ix_huya_recharge_goods_snapshot_sku_id",
"huya_recharge_goods_snapshot",
["sku_id"],
)
def downgrade() -> None:
bind = op.get_bind()
if _has_table(bind, "huya_recharge_goods_snapshot"):
indexes = _indexes(bind, "huya_recharge_goods_snapshot")
if "ix_huya_recharge_goods_snapshot_sku_id" in indexes:
op.drop_index("ix_huya_recharge_goods_snapshot_sku_id", table_name="huya_recharge_goods_snapshot")
if "ix_huya_recharge_goods_snapshot_spu_id" in indexes:
op.drop_index("ix_huya_recharge_goods_snapshot_spu_id", table_name="huya_recharge_goods_snapshot")
op.drop_table("huya_recharge_goods_snapshot")