"""V17 对齐 V16 已应用工作区约束的完整表名约定。""" from alembic import op revision: str = "07b8c9d0e1f2" down_revision: str | None = "f6a708b9c0d1" branch_labels = None depends_on = None RENAMES = ( ("tplus_source_heads", "uk_tplus_heads_source_entity_id", "uk_tplus_source_heads_source_entity_id"), ("tplus_source_heads", "idx_tplus_heads_batch_entity", "idx_tplus_source_heads_batch_entity"), ("tplus_source_links", "uk_tplus_links_source_entity_id", "uk_tplus_source_links_source_entity_id"), ("tplus_source_links", "uk_tplus_links_entity_target", "uk_tplus_source_links_entity_target"), ) def upgrade(): """只重命名固定索引,不改变任何数据。""" for table, old, new in RENAMES: op.execute(f"ALTER TABLE {table} RENAME INDEX {old} TO {new}") def downgrade(): """恢复 V16 固定索引名。""" for table, old, new in reversed(RENAMES): op.execute(f"ALTER TABLE {table} RENAME INDEX {new} TO {old}")