feat(shipping-notice): 增加发货通知建单幂等性支持及内容哈希校验

This commit is contained in:
hugo committed 2026-07-14 00:28:52 +08:00
1 parent 0a9bd6415d
commit 143e054d86
39 files changed
+1750 -80

No files matched your search

@@ -0,0 +1,48 @@
"""
backend/migrations/versions/e7f8a9b0c1d2_add_shipping_batch_creation_idempotency.py
用途:发货通知建单幂等键与源文件 SHA-256 内容哈希字段。
依赖:Alembic revision d6e7f8a9b0c1。
逻辑:shipping_batches.create_idempotency_key 唯一约束;shipping_tasks.source_content_hash 查询索引。
Revision ID: e7f8a9b0c1d2
Revises: d6e7f8a9b0c1
Create Date: 2026-07-13 22:30:00.000000
"""
from __future__ import annotations
import sqlalchemy as sa
from alembic import op
revision = "e7f8a9b0c1d2"
down_revision = "d6e7f8a9b0c1"
branch_labels = None
depends_on = None
def upgrade() -> None:
with op.batch_alter_table("shipping_batches", schema=None) as batch_op:
batch_op.add_column(sa.Column("create_idempotency_key", sa.String(length=128), nullable=True))
batch_op.create_unique_constraint(
"uq_shipping_batches_user_create_idempotency",
["user_id", "create_idempotency_key"],
)
with op.batch_alter_table("shipping_tasks", schema=None) as batch_op:
batch_op.add_column(sa.Column("source_content_hash", sa.String(length=64), nullable=True))
batch_op.create_index(
"ix_shipping_tasks_user_source_content_hash",
["user_id", "source_content_hash"],
unique=False,
)
def downgrade() -> None:
with op.batch_alter_table("shipping_tasks", schema=None) as batch_op:
batch_op.drop_index("ix_shipping_tasks_user_source_content_hash")
batch_op.drop_column("source_content_hash")
with op.batch_alter_table("shipping_batches", schema=None) as batch_op:
batch_op.drop_constraint("uq_shipping_batches_user_create_idempotency", type_="unique")
batch_op.drop_column("create_idempotency_key")