Files
junhong_cmp_fiber/migrations/000108_iot_card_virtual_no_optional.up.sql
huang 14a8ea5a2c
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m26s
fix: 单卡导入虚拟号改为可选,非空时保证全局唯一
2026-04-08 10:45:23 +08:00

14 lines
729 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 将 tb_iot_card.virtual_no 恢复为可选字段(可为空)
-- 背景:业务确认单卡导入时虚拟号非必填,不能强制要求
-- 步骤1. 删除无条件唯一索引2. 移除 NOT NULL 约束3. 重建条件唯一索引(允许多条空值共存)
-- 删除当前无条件唯一索引
DROP INDEX IF EXISTS idx_iot_card_virtual_no;
-- 将 virtual_no 列改回允许 NULL
ALTER TABLE tb_iot_card ALTER COLUMN virtual_no DROP NOT NULL;
-- 重建条件唯一索引(仅对非空、非空字符串的值保证唯一;允许多条空值/NULL 共存)
CREATE UNIQUE INDEX idx_iot_card_virtual_no ON tb_iot_card(virtual_no)
WHERE deleted_at IS NULL AND virtual_no IS NOT NULL AND virtual_no <> '';