"""Drop the unique constraint on ``asset_legal_entities.code`` introduced in migration 132. Reason: in practice multiple Chinese legal entities (e.g. 北京星云 深图 / 平凯星辰 北京 / 北京平凯星辰) all share the same ``CN`` country slug from the asset-tag generation rule ``IT-{code}-{cat_no_p}-{YYYYMMDDHHMMSS}``. Forcing global uniqueness would compel admins to invent fake-distinct codes per entity (``CN1`` / ``CN2`` / ``CN3``) that leak into asset tags as meaningless noise. Tag uniqueness is preserved by the timestamp suffix + the ``asset_items.asset_tag`` UNIQUE column constraint at the asset row level — the entity ``code`` only contributes its 2nd-segment prefix and is not required to be unique. Schema-only — no data backfill. """ from __future__ import annotations from alembic import op revision = "133" down_revision = "132" branch_labels = None depends_on = None def upgrade() -> None: op.drop_index( "uq_asset_legal_entities_code", table_name="asset_legal_entities", ) def downgrade() -> None: op.create_index( "uq_asset_legal_entities_code", "asset_legal_entities", ["code"], unique=True, )