Files
smart_grid_iot/database/migrations/20261016_icc_customer_sync.sql
T

22 lines
1.1 KiB
PL/PgSQL
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.
-- ICC 客户信息同步(第一阶段):
-- 1) 幂等新增 customer.icc_code 列(ICC 平台 orgCode,作为 ICC 同步的幂等匹配键)
-- 2) 幂等创建唯一索引 uk_customer_icc_code(icc_code 可空,PostgreSQL 下多个 NULL 不冲突)
BEGIN;
-- ------------------------------------------------------------
-- 1) 新增列 icc_code(可空,幂等;与 db_init.sql / customer.entity.ts 保持一致)
-- ------------------------------------------------------------
ALTER TABLE customer ADD COLUMN IF NOT EXISTS icc_code VARCHAR(64);
-- ------------------------------------------------------------
-- 2) 唯一索引(icc_code 可空,PostgreSQL 中多个 NULL 不冲突,唯一索引安全)
-- ------------------------------------------------------------
CREATE UNIQUE INDEX IF NOT EXISTS uk_customer_icc_code ON customer (icc_code);
-- ------------------------------------------------------------
-- 3) 列注释
-- ------------------------------------------------------------
COMMENT ON COLUMN customer.icc_code IS 'ICC客户编码(ICC平台 orgCode,同步来源)';
COMMIT;