Files
syops/backend/migrations/versions/f0f24c20e91a_add_userhomepageconfig_.py
T
hugo 8deae3146b feat(shipping-notice): 完成货代发货通知全流程开发与代码重构
- 新增PO号提取、预约ID解析(支持`PR@xxx`格式)工具,完善库存匹配逻辑
- 新增库存映射缓存、匹配/解析结果格式化摘要,优化用户提示
- 修复数据库迁移脚本未检查表存在的问题,避免全新部署失败
- 新增路径工具类统一管理相对路径,优化配置文件处理逻辑
- 归档旧文档,将部署、Dify配置合并到`shipping_notice.md`
- 新增完整单元测试与集成测试覆盖核心流程
- 更新前端国际化与会话管理逻辑,优化界面交互
2026-06-04 15:26:34 +08:00

87 lines
3.3 KiB
Python

"""Add UserHomepageConfig, UserFavoriteAgent, UserDefaultAgent and Update Department
Revision ID: f0f24c20e91a
Revises: 60b4aee3ad2d
Create Date: 2026-02-23 21:13:19.814958
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f0f24c20e91a'
down_revision = '60b4aee3ad2d'
branch_labels = None
depends_on = None
def upgrade():
conn = op.get_bind()
insp = sa.inspect(conn)
tables = set(insp.get_table_names())
if 'users' in tables and 'agents' in tables:
if 'user_default_agents' not in tables:
op.create_table(
'user_default_agents',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('agent_id', sa.Integer(), nullable=False),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['agent_id'], ['agents.id']),
sa.ForeignKeyConstraint(['user_id'], ['users.id']),
sa.PrimaryKeyConstraint('id'),
)
if 'user_favorite_agents' not in tables:
op.create_table(
'user_favorite_agents',
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('agent_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['agent_id'], ['agents.id']),
sa.ForeignKeyConstraint(['user_id'], ['users.id']),
sa.PrimaryKeyConstraint('user_id', 'agent_id'),
)
if 'user_homepage_configs' not in tables:
op.create_table(
'user_homepage_configs',
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('layout', sa.JSON(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id']),
sa.PrimaryKeyConstraint('user_id'),
)
if 'departments' in tables:
cols = {c['name'] for c in insp.get_columns('departments')}
with op.batch_alter_table('departments', schema=None) as batch_op:
if 'code' not in cols:
batch_op.add_column(sa.Column('code', sa.String(length=50), nullable=True))
batch_op.create_unique_constraint(None, ['code'])
if 'company' not in cols:
batch_op.add_column(sa.Column('company', sa.String(length=100), nullable=True))
def downgrade():
conn = op.get_bind()
insp = sa.inspect(conn)
tables = set(insp.get_table_names())
if 'departments' in tables:
cols = {c['name'] for c in insp.get_columns('departments')}
with op.batch_alter_table('departments', schema=None) as batch_op:
if 'code' in cols:
try:
batch_op.drop_constraint(None, type_='unique')
except Exception:
pass
batch_op.drop_column('code')
if 'company' in cols:
batch_op.drop_column('company')
for tbl in ('user_homepage_configs', 'user_favorite_agents', 'user_default_agents'):
if tbl in tables:
op.drop_table(tbl)