Syncs the event-lead-capture and lead-interests specs into main specs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
65 lines
2.5 KiB
SQL
65 lines
2.5 KiB
SQL
-- Co-Lite change 4a: leads, event leads and interests.
|
|
-- Target: `service-counter`. Additive only. Run once.
|
|
-- salesperson_user_id points at `service-system`.`user` and event_uuid at `event`; no foreign keys, mobile-api checks them on write.
|
|
-- interest.name is unique per company; the utf8mb4 default collation makes that case-insensitive.
|
|
USE `service-counter`;
|
|
|
|
CREATE TABLE `lead` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`uuid` bigint NOT NULL,
|
|
`company_id` bigint NOT NULL,
|
|
`name` varchar(100) NOT NULL,
|
|
`mobile_e164` varchar(20) DEFAULT NULL,
|
|
`email_normalised` varchar(254) DEFAULT NULL,
|
|
`company_name` varchar(150) DEFAULT NULL,
|
|
`job_title` varchar(100) DEFAULT NULL,
|
|
`notes` text,
|
|
`created_by` varchar(255) DEFAULT NULL,
|
|
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_by` varchar(255) DEFAULT NULL,
|
|
`updated_at` datetime DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_lead_uuid` (`uuid`),
|
|
KEY `idx_lead_company_mobile` (`company_id`, `mobile_e164`),
|
|
KEY `idx_lead_company_email` (`company_id`, `email_normalised`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
CREATE TABLE `event_lead` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`uuid` bigint NOT NULL,
|
|
`company_id` bigint NOT NULL,
|
|
`event_uuid` bigint NOT NULL,
|
|
`lead_uuid` bigint NOT NULL,
|
|
`salesperson_user_id` bigint DEFAULT NULL,
|
|
`lead_type` varchar(8) NOT NULL,
|
|
`temperature` varchar(4) DEFAULT NULL,
|
|
`status` varchar(10) NOT NULL DEFAULT 'OPEN',
|
|
`next_follow_up_date` date DEFAULT NULL,
|
|
`notes` text,
|
|
`captured_by` varchar(255) DEFAULT NULL,
|
|
`captured_at` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_by` varchar(255) DEFAULT NULL,
|
|
`updated_at` datetime DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_event_lead_uuid` (`uuid`),
|
|
UNIQUE KEY `uk_event_lead_event_lead` (`event_uuid`, `lead_uuid`),
|
|
KEY `idx_event_lead_company_event` (`company_id`, `event_uuid`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
CREATE TABLE `interest` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`company_id` bigint NOT NULL,
|
|
`name` varchar(100) NOT NULL,
|
|
`active` bit(1) NOT NULL DEFAULT b'1',
|
|
`sort_order` int NOT NULL DEFAULT 0,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_interest_company_name` (`company_id`, `name`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
CREATE TABLE `event_lead_interest` (
|
|
`event_lead_id` bigint NOT NULL,
|
|
`interest_id` bigint NOT NULL,
|
|
`company_id` bigint NOT NULL,
|
|
PRIMARY KEY (`event_lead_id`, `interest_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|