-- 客户加工方式别名映射:客户叫法 → 标准加工方式 CREATE TABLE IF NOT EXISTS customer_processing_aliases ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), customer_code VARCHAR(50) NOT NULL REFERENCES customers(customer_code), alias_name VARCHAR(100) NOT NULL, processing_method VARCHAR(100) NOT NULL, is_primary BOOLEAN DEFAULT false, usage_count INTEGER DEFAULT 0, confidence_score DECIMAL(5,2) DEFAULT 100.00, status INTEGER DEFAULT 1, created_at TIMESTAMPTZ DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT NOW(), UNIQUE(customer_code, alias_name) ); CREATE INDEX IF NOT EXISTS idx_customer_processing_aliases_customer ON customer_processing_aliases(customer_code); CREATE INDEX IF NOT EXISTS idx_customer_processing_aliases_alias ON customer_processing_aliases(alias_name); ALTER TABLE customer_processing_aliases ENABLE ROW LEVEL SECURITY; DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_policies WHERE schemaname = 'public' AND tablename = 'customer_processing_aliases' AND policyname = 'anon_all_customer_processing_aliases' ) THEN CREATE POLICY anon_all_customer_processing_aliases ON customer_processing_aliases FOR ALL USING (true); END IF; END $$; COMMENT ON TABLE customer_processing_aliases IS '客户加工方式别名:客户叫法映射到标准加工方式,用于语音/图片录单解析';