mirror of
https://git.oceanpay.cc/danial/kami_apple_exchage.git
synced 2025-12-18 22:29:09 +00:00
-移除健康检查、配置管理、用户管理和Playwright服务等旧端点 - 添加扩展健康检查、订单管理和批量任务等新端点 - 更新数据库模型,将UUID改为32位无连接符的字符串 - 重构配置相关代码,改为使用环境变量和YAML配置 - 优化日志配置,添加日志轮转和保留策略 - 添加健康检查和监控相关配置
174 lines
5.3 KiB
Python
174 lines
5.3 KiB
Python
"""Add batch tasks tables
|
|
|
|
Revision ID: 002
|
|
Revises: 001
|
|
Create Date: 2024-08-24 22:00:00.000000
|
|
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = "002"
|
|
down_revision = "001"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Create batch_tasks table
|
|
op.create_table(
|
|
"batch_tasks",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column(
|
|
"name", sa.String(length=255), nullable=False, comment="批量任务名称"
|
|
),
|
|
sa.Column("description", sa.Text(), nullable=True, comment="任务描述"),
|
|
sa.Column(
|
|
"status",
|
|
sa.Enum(
|
|
"PENDING",
|
|
"PROCESSING",
|
|
"COMPLETED",
|
|
"FAILED",
|
|
"CANCELLED",
|
|
name="batchtaskstatus",
|
|
),
|
|
nullable=True,
|
|
comment="任务状态",
|
|
),
|
|
sa.Column("total_count", sa.Integer(), nullable=True, comment="总任务数量"),
|
|
sa.Column("processed_count", sa.Integer(), nullable=True, comment="已处理数量"),
|
|
sa.Column("success_count", sa.Integer(), nullable=True, comment="成功数量"),
|
|
sa.Column("failed_count", sa.Integer(), nullable=True, comment="失败数量"),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.text("now()"),
|
|
nullable=True,
|
|
comment="创建时间",
|
|
),
|
|
sa.Column(
|
|
"updated_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.text("now()"),
|
|
nullable=True,
|
|
comment="更新时间",
|
|
),
|
|
sa.Column(
|
|
"started_at",
|
|
sa.DateTime(timezone=True),
|
|
nullable=True,
|
|
comment="开始处理时间",
|
|
),
|
|
sa.Column(
|
|
"completed_at",
|
|
sa.DateTime(timezone=True),
|
|
nullable=True,
|
|
comment="完成时间",
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_batch_tasks_id"), "batch_tasks", ["id"], unique=False)
|
|
|
|
# Create batch_task_items table
|
|
op.create_table(
|
|
"batch_task_items",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("batch_task_id", sa.Integer(), nullable=False, comment="批量任务ID"),
|
|
sa.Column(
|
|
"order_url", sa.String(length=1000), nullable=False, comment="订单链接"
|
|
),
|
|
sa.Column(
|
|
"amount",
|
|
sa.Numeric(precision=10, scale=2),
|
|
nullable=False,
|
|
comment="订单金额",
|
|
),
|
|
sa.Column(
|
|
"status",
|
|
sa.Enum(
|
|
"PENDING",
|
|
"PROCESSING",
|
|
"SUCCESS",
|
|
"FAILED",
|
|
"SKIPPED",
|
|
name="batchtaskitemstatus",
|
|
),
|
|
nullable=True,
|
|
comment="任务项状态",
|
|
),
|
|
sa.Column(
|
|
"order_number", sa.String(length=255), nullable=True, comment="生成的订单号"
|
|
),
|
|
sa.Column(
|
|
"final_order_url",
|
|
sa.String(length=1000),
|
|
nullable=True,
|
|
comment="最终订单URL",
|
|
),
|
|
sa.Column("failure_reason", sa.Text(), nullable=True, comment="失败原因"),
|
|
sa.Column("retry_count", sa.Integer(), nullable=True, comment="重试次数"),
|
|
sa.Column("max_retries", sa.Integer(), nullable=True, comment="最大重试次数"),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.text("now()"),
|
|
nullable=True,
|
|
comment="创建时间",
|
|
),
|
|
sa.Column(
|
|
"updated_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.text("now()"),
|
|
nullable=True,
|
|
comment="更新时间",
|
|
),
|
|
sa.Column(
|
|
"started_at",
|
|
sa.DateTime(timezone=True),
|
|
nullable=True,
|
|
comment="开始处理时间",
|
|
),
|
|
sa.Column(
|
|
"completed_at",
|
|
sa.DateTime(timezone=True),
|
|
nullable=True,
|
|
comment="完成时间",
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.ForeignKeyConstraint(
|
|
["batch_task_id"], ["batch_tasks.id"], ondelete="CASCADE"
|
|
),
|
|
)
|
|
op.create_index(
|
|
op.f("ix_batch_task_items_id"), "batch_task_items", ["id"], unique=False
|
|
)
|
|
op.create_index(
|
|
"ix_batch_task_items_batch_task_id",
|
|
"batch_task_items",
|
|
["batch_task_id"],
|
|
unique=False,
|
|
)
|
|
op.create_index(
|
|
"ix_batch_task_items_status", "batch_task_items", ["status"], unique=False
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
# Drop indexes
|
|
op.drop_index("ix_batch_task_items_status", table_name="batch_task_items")
|
|
op.drop_index("ix_batch_task_items_batch_task_id", table_name="batch_task_items")
|
|
op.drop_index(op.f("ix_batch_task_items_id"), table_name="batch_task_items")
|
|
op.drop_index(op.f("ix_batch_tasks_id"), table_name="batch_tasks")
|
|
|
|
# Drop tables
|
|
op.drop_table("batch_task_items")
|
|
op.drop_table("batch_tasks")
|
|
|
|
# Drop enums
|
|
op.execute("DROP TYPE IF EXISTS batchtaskitemstatus")
|
|
op.execute("DROP TYPE IF EXISTS batchtaskstatus")
|