"""Merge external-account classifications service_account + shared_mailbox → shared_service. Revision ID: 372 Revises: 371 Create Date: 2026-07-01 The 外部/共用账号 registry collapses the two "public service" buckets into one 公共服务(团队使用) classification. ``service_account`` (bot / CI / service account) and ``shared_mailbox`` (finance@, support@, …) were never operationally distinct — both are team-shared, both counted as known/ expected. Re-key every existing row to ``shared_service``. Idempotent UPDATE, no schema change (``classification`` is a free String column). Downgrade cannot recover the original two-way split (information was lost by merging), so it best-effort maps everything back to ``service_account``. """ from __future__ import annotations import sqlalchemy as sa from alembic import op revision = "372" down_revision = "371" branch_labels = None depends_on = None _TABLE = "external_account_registry" def upgrade() -> None: bind = op.get_bind() bind.execute( sa.text( f"UPDATE {_TABLE} SET classification = 'shared_service' " "WHERE classification IN ('service_account', 'shared_mailbox')" ) ) def downgrade() -> None: bind = op.get_bind() bind.execute( sa.text( f"UPDATE {_TABLE} SET classification = 'service_account' " "WHERE classification = 'shared_service'" ) )