bmc_hub/migrations/032_opportunity_emails_m2m.sql

11 lines
467 B
MySQL
Raw Normal View History

2026-01-29 00:36:32 +01:00
CREATE TABLE IF NOT EXISTS pipeline_opportunity_emails (
opportunity_id INTEGER REFERENCES pipeline_opportunities(id) ON DELETE CASCADE,
email_id INTEGER REFERENCES email_messages(id) ON DELETE CASCADE,
created_at TIMESTAMPTZ DEFAULT NOW(),
PRIMARY KEY (opportunity_id, email_id)
);
INSERT INTO pipeline_opportunity_emails (opportunity_id, email_id)
SELECT id, email_id FROM pipeline_opportunities WHERE email_id IS NOT NULL
ON CONFLICT DO NOTHING;