bmc_hub/migrations/170_email_domain_customer_mappings.sql
Christian 8e8616c835 feat: Enhance vendor and customer linking functionality
- Added endpoints to link and unlink customers to vendors, including validation for relationship types.
- Implemented a UI for managing linked customers in the vendor detail view.
- Introduced a search feature for customers when linking to vendors.
- Updated database schema to support customer-vendor relationships with necessary constraints and indices.
- Added migration scripts for new tables and fields related to supplier invoices and customer-vendor links.
- Modified bottom bar visibility in the frontend for improved user experience.
2026-04-15 09:34:26 +02:00

34 lines
1.4 KiB
PL/PgSQL

-- Migration 170: Trusted sender-domain to customer mappings for email triage
-- Created: 2026-04-12
CREATE TABLE IF NOT EXISTS email_domain_customer_mappings (
domain VARCHAR(255) PRIMARY KEY,
customer_id INTEGER NOT NULL REFERENCES customers(id) ON DELETE CASCADE,
source VARCHAR(50) NOT NULL DEFAULT 'manual',
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_email_domain_customer_mappings_customer_id
ON email_domain_customer_mappings(customer_id);
CREATE INDEX IF NOT EXISTS idx_email_domain_customer_mappings_source
ON email_domain_customer_mappings(source);
CREATE OR REPLACE FUNCTION update_email_domain_customer_mappings_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS trigger_email_domain_customer_mappings_updated_at ON email_domain_customer_mappings;
CREATE TRIGGER trigger_email_domain_customer_mappings_updated_at
BEFORE UPDATE ON email_domain_customer_mappings
FOR EACH ROW
EXECUTE FUNCTION update_email_domain_customer_mappings_updated_at();
COMMENT ON TABLE email_domain_customer_mappings IS 'Trusted mappings from sender email domain to customer for fast auto-linking in email triage';
COMMENT ON COLUMN email_domain_customer_mappings.source IS 'manual, auto_link, import, etc.';