fix: 修复知识库唯一约束迁移兼容性

This commit is contained in:
2026-07-12 15:31:17 +08:00
parent 8266d845c0
commit e337897b7a

View File

@@ -1,20 +1,25 @@
from __future__ import annotations from __future__ import annotations
from alembic import op from alembic import op
import sqlalchemy as sa
revision = "0008_unique_knowledge_feishu_node" revision = "0008_unique_kb_node"
down_revision = "0007_knowledge_agent_rebuild" down_revision = "0007_knowledge_agent_rebuild"
branch_labels = None branch_labels = None
depends_on = None depends_on = None
def upgrade() -> None: def upgrade() -> None:
op.create_unique_constraint( constraints = {item["name"] for item in sa.inspect(op.get_bind()).get_unique_constraints("sys_knowledge")}
"uq_knowledge_feishu_node", if "uq_knowledge_feishu_node" not in constraints:
"sys_knowledge", op.create_unique_constraint(
["feishu_space_id", "feishu_node_id"], "uq_knowledge_feishu_node",
) "sys_knowledge",
["feishu_space_id", "feishu_node_id"],
)
def downgrade() -> None: def downgrade() -> None:
op.drop_constraint("uq_knowledge_feishu_node", "sys_knowledge", type_="unique") constraints = {item["name"] for item in sa.inspect(op.get_bind()).get_unique_constraints("sys_knowledge")}
if "uq_knowledge_feishu_node" in constraints:
op.drop_constraint("uq_knowledge_feishu_node", "sys_knowledge", type_="unique")