"""update role template copy Revision ID: 20260522_01 Revises: 20260521_01 Create Date: 2026-05-22 09:00:00.000000 """ from typing import Sequence, Union from alembic import op revision: str = "20260522_01" down_revision: Union[str, None] = "20260521_01" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None ROLE_TEMPLATE_COPY = { "PM": ("PM", "项目负责人,统筹项目全局,协调进度、资源与关键决策。"), "CRA": ("CRA", "负责各中心临床监查执行,跟进现场质量、数据和问题闭环。"), "IMP": ("CTA", "负责合同、药品及相关项目事务管理,保障执行支持与物资协同。"), "MEDICAL_REVIEW": ("QA", "负责医学审核与稽查,关注质量风险、合规性和医学一致性。"), "PV": ("PV", "负责药物警戒相关工作,跟踪安全性事件并支持风险评估。"), } PREVIOUS_ROLE_TEMPLATE_COPY = { "PM": ("项目经理", "项目管理员,拥有所有权限"), "CRA": ("临床研究协调员", "数据输入和日常管理人员"), "IMP": ("物资管理员", "物资和设备管理人员"), "MEDICAL_REVIEW": ("医学审核", "医学审核人员"), "PV": ("访视员", "访视和参与者管理人员"), } def _update_role_copy(category: str, name: str, description: str) -> None: op.execute( f""" UPDATE permission_templates SET name = '{name}', description = '{description}', updated_at = NOW() WHERE category = '{category}' AND template_type = 'ROLE' AND is_system = true """ ) def upgrade() -> None: for category, (name, description) in ROLE_TEMPLATE_COPY.items(): _update_role_copy(category, name, description) def downgrade() -> None: for category, (name, description) in PREVIOUS_ROLE_TEMPLATE_COPY.items(): _update_role_copy(category, name, description)