Files
junhong_cmp_fiber/migrations/000108_iot_card_virtual_no_optional.down.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
499 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 恢复为 NOT NULL并重建无条件唯一索引
-- 清理空值记录(如有)
DELETE FROM tb_iot_card WHERE virtual_no IS NULL OR virtual_no = '';
-- 删除条件唯一索引
DROP INDEX IF EXISTS idx_iot_card_virtual_no;
-- 将 virtual_no 列改为 NOT NULL
ALTER TABLE tb_iot_card ALTER COLUMN virtual_no SET NOT NULL;
-- 重建无条件唯一索引
CREATE UNIQUE INDEX idx_iot_card_virtual_no ON tb_iot_card(virtual_no) WHERE deleted_at IS NULL;