feat(shipping-notice): 支持发货通知解析延后至 Dify 画布,优化任务创建流程
This commit is contained in:
1 parent
d46d61bfa1
commit
70e8f700ff
38 files changed
+3215
-714
No files matched your search
+112
@@ -0,0 +1,112 @@
|
||||
"""align shipping_tasks schema drift
|
||||
|
||||
Revision ID: e2f4a6b8c0d1
|
||||
Revises: c5d6e7f8a9b0
|
||||
Create Date: 2026-06-22 09:10:00.000000
|
||||
|
||||
用途:一次性修复 shipping_tasks 在部分 PostgreSQL 环境里的 schema 漂移,使其与当前 ShippingTask 模型保持一致。
|
||||
依赖:Alembic op / SQLAlchemy inspect;与 ShippingTask 模型、既有建单/编辑逻辑保持一致。
|
||||
逻辑:upgrade 恢复 upload_status/upload_mode 的可空语义,并对齐 source_file_type 长度、export_version 默认值;downgrade 提供对称回滚。
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = "e2f4a6b8c0d1"
|
||||
down_revision = "c5d6e7f8a9b0"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _table_columns(insp, table_name: str) -> set[str]:
|
||||
if table_name not in set(insp.get_table_names()):
|
||||
return set()
|
||||
return {col["name"] for col in insp.get_columns(table_name)}
|
||||
|
||||
|
||||
def upgrade():
|
||||
bind = op.get_bind()
|
||||
insp = sa.inspect(bind)
|
||||
|
||||
columns = _table_columns(insp, "shipping_tasks")
|
||||
if not columns:
|
||||
return
|
||||
|
||||
# [STEP 1] 恢复上传相关字段的可空语义,与模型/状态机现状保持一致。
|
||||
with op.batch_alter_table("shipping_tasks", schema=None) as batch_op:
|
||||
if "upload_status" in columns:
|
||||
batch_op.alter_column(
|
||||
"upload_status",
|
||||
existing_type=sa.String(length=32),
|
||||
nullable=True,
|
||||
)
|
||||
if "upload_mode" in columns:
|
||||
batch_op.alter_column(
|
||||
"upload_mode",
|
||||
existing_type=sa.String(length=32),
|
||||
nullable=True,
|
||||
)
|
||||
|
||||
# [STEP 2] 对齐字段长度与默认值,避免模型/数据库继续出现隐性分叉。
|
||||
with op.batch_alter_table("shipping_tasks", schema=None) as batch_op:
|
||||
if "source_file_type" in columns:
|
||||
batch_op.alter_column(
|
||||
"source_file_type",
|
||||
existing_type=sa.String(length=32),
|
||||
type_=sa.String(length=64),
|
||||
existing_nullable=True,
|
||||
)
|
||||
if "export_version" in columns:
|
||||
batch_op.alter_column(
|
||||
"export_version",
|
||||
existing_type=sa.Integer(),
|
||||
server_default="1",
|
||||
existing_nullable=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
bind = op.get_bind()
|
||||
insp = sa.inspect(bind)
|
||||
|
||||
columns = _table_columns(insp, "shipping_tasks")
|
||||
if not columns:
|
||||
return
|
||||
|
||||
# [STEP 1] 先回滚长度与默认值,恢复升级前的库侧行为。
|
||||
with op.batch_alter_table("shipping_tasks", schema=None) as batch_op:
|
||||
if "source_file_type" in columns:
|
||||
batch_op.alter_column(
|
||||
"source_file_type",
|
||||
existing_type=sa.String(length=64),
|
||||
type_=sa.String(length=32),
|
||||
existing_nullable=True,
|
||||
)
|
||||
if "export_version" in columns:
|
||||
batch_op.alter_column(
|
||||
"export_version",
|
||||
existing_type=sa.Integer(),
|
||||
server_default="0",
|
||||
existing_nullable=False,
|
||||
)
|
||||
|
||||
# [STEP 2] 回滚为 NOT NULL 前先补齐现存 NULL,避免约束恢复时失败。
|
||||
if "upload_status" in columns:
|
||||
op.execute("UPDATE shipping_tasks SET upload_status = '' WHERE upload_status IS NULL")
|
||||
if "upload_mode" in columns:
|
||||
op.execute("UPDATE shipping_tasks SET upload_mode = '' WHERE upload_mode IS NULL")
|
||||
|
||||
with op.batch_alter_table("shipping_tasks", schema=None) as batch_op:
|
||||
if "upload_status" in columns:
|
||||
batch_op.alter_column(
|
||||
"upload_status",
|
||||
existing_type=sa.String(length=32),
|
||||
nullable=False,
|
||||
)
|
||||
if "upload_mode" in columns:
|
||||
batch_op.alter_column(
|
||||
"upload_mode",
|
||||
existing_type=sa.String(length=32),
|
||||
nullable=False,
|
||||
)
|
||||
@@ -0,0 +1,108 @@
|
||||
"""apply shipping_tasks schema alignment
|
||||
|
||||
Revision ID: f1e2d3c4b5a6
|
||||
Revises: e2f4a6b8c0d1
|
||||
Create Date: 2026-06-22 09:45:00.000000
|
||||
|
||||
用途:将已处于 e2f4a6b8c0d1 版本、但未实际应用 shipping_tasks 字段对齐的数据库补齐到目标结构。
|
||||
依赖:Alembic op / SQLAlchemy inspect;用于修复已执行 revision 文件被后改导致的实际库结构未变问题。
|
||||
逻辑:upgrade 真正落地 upload_mode/upload_status/source_file_type/export_version 的对齐;downgrade 回退到当前本地库观测到的旧结构。
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = "f1e2d3c4b5a6"
|
||||
down_revision = "e2f4a6b8c0d1"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _table_columns(insp, table_name: str) -> set[str]:
|
||||
if table_name not in set(insp.get_table_names()):
|
||||
return set()
|
||||
return {col["name"] for col in insp.get_columns(table_name)}
|
||||
|
||||
|
||||
def upgrade():
|
||||
bind = op.get_bind()
|
||||
insp = sa.inspect(bind)
|
||||
|
||||
columns = _table_columns(insp, "shipping_tasks")
|
||||
if not columns:
|
||||
return
|
||||
|
||||
with op.batch_alter_table("shipping_tasks", schema=None) as batch_op:
|
||||
if "upload_status" in columns:
|
||||
batch_op.alter_column(
|
||||
"upload_status",
|
||||
existing_type=sa.String(length=32),
|
||||
nullable=True,
|
||||
server_default=None,
|
||||
)
|
||||
if "upload_mode" in columns:
|
||||
batch_op.alter_column(
|
||||
"upload_mode",
|
||||
existing_type=sa.String(length=32),
|
||||
nullable=True,
|
||||
server_default=None,
|
||||
)
|
||||
if "source_file_type" in columns:
|
||||
batch_op.alter_column(
|
||||
"source_file_type",
|
||||
existing_type=sa.String(length=32),
|
||||
type_=sa.String(length=64),
|
||||
existing_nullable=True,
|
||||
)
|
||||
if "export_version" in columns:
|
||||
batch_op.alter_column(
|
||||
"export_version",
|
||||
existing_type=sa.Integer(),
|
||||
server_default="1",
|
||||
existing_nullable=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
bind = op.get_bind()
|
||||
insp = sa.inspect(bind)
|
||||
|
||||
columns = _table_columns(insp, "shipping_tasks")
|
||||
if not columns:
|
||||
return
|
||||
|
||||
if "upload_mode" in columns:
|
||||
op.execute("UPDATE shipping_tasks SET upload_mode = 'auto' WHERE upload_mode IS NULL")
|
||||
if "upload_status" in columns:
|
||||
op.execute("UPDATE shipping_tasks SET upload_status = 'not_started' WHERE upload_status IS NULL")
|
||||
|
||||
with op.batch_alter_table("shipping_tasks", schema=None) as batch_op:
|
||||
if "upload_status" in columns:
|
||||
batch_op.alter_column(
|
||||
"upload_status",
|
||||
existing_type=sa.String(length=32),
|
||||
nullable=True,
|
||||
server_default="not_started",
|
||||
)
|
||||
if "upload_mode" in columns:
|
||||
batch_op.alter_column(
|
||||
"upload_mode",
|
||||
existing_type=sa.String(length=32),
|
||||
nullable=False,
|
||||
server_default="auto",
|
||||
)
|
||||
if "source_file_type" in columns:
|
||||
batch_op.alter_column(
|
||||
"source_file_type",
|
||||
existing_type=sa.String(length=64),
|
||||
type_=sa.String(length=32),
|
||||
existing_nullable=True,
|
||||
)
|
||||
if "export_version" in columns:
|
||||
batch_op.alter_column(
|
||||
"export_version",
|
||||
existing_type=sa.Integer(),
|
||||
server_default="0",
|
||||
existing_nullable=False,
|
||||
)
|
||||
Reference in new issue
Block a user