Files
junhong_cmp_fiber/migrations/archive/000105_create_asset_identifier.up.sql

15 lines
874 B
SQL
Raw Permalink 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.
-- 创建全局资产标识符注册表,保证 ICCID/VirtualNo 跨 tb_iot_card 和 tb_device 全局唯一
CREATE TABLE IF NOT EXISTS tb_asset_identifier (
id BIGSERIAL PRIMARY KEY,
identifier VARCHAR(100) NOT NULL,
asset_type VARCHAR(20) NOT NULL,
asset_id BIGINT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT uq_asset_identifier UNIQUE (identifier)
);
CREATE INDEX IF NOT EXISTS idx_asset_identifier_asset ON tb_asset_identifier(asset_type, asset_id);
COMMENT ON TABLE tb_asset_identifier IS '全局资产标识符注册表';
COMMENT ON COLUMN tb_asset_identifier.identifier IS '标识符值ICCID 或 VirtualNo全局唯一';
COMMENT ON COLUMN tb_asset_identifier.asset_type IS '资产类型iot_card 或 device';
COMMENT ON COLUMN tb_asset_identifier.asset_id IS '对应资产的主键 ID';