fix: 单卡导入虚拟号改为可选,非空时保证全局唯一
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m26s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m26s
This commit is contained in:
13
migrations/000108_iot_card_virtual_no_optional.up.sql
Normal file
13
migrations/000108_iot_card_virtual_no_optional.up.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
-- 将 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 <> '';
|
||||
Reference in New Issue
Block a user