5.2 KiB
Task D.5.1: Lead Foundation Stabilization & Output Completion
Objective
Audit the existing D.5 phase-1 lead foundation work, avoid duplicate schema creation, complete missing registration outputs, and confirm current CRM compatibility before D.5.2 lead API work begins.
Review Completed
AGENTS.mddocs/standards/project-foundations.mddocs/standards/task-catalog.mddocs/adr/0018-lead-enquiry-domain-separation.mddocs/implementation/task-d5-lead-enquiry-domain-separation.mdsrc/db/schema.tssrc/db/seeds/foundation.seed.tsdrizzle/0020_lead_foundation_schema.sqldrizzle/0021_worried_nebula.sqldrizzle/meta/_journal.jsonsrc/features/foundation/master-options/types.tssrc/features/foundation/document-sequence/service.ts
Existing Foundation
Verified present in the repository:
crm_leadsexists in schema.tscrm_enquiries.lead_idexists in schema.ts- ADR-0018 exists at 0018-lead-enquiry-domain-separation.md
- lead seed categories already exist in foundation.seed.ts:
crm_lead_awarenesscrm_lead_statuscrm_lead_followup_statuscrm_lead_lost_reason
- document sequence defaults already include:
crm_leadcrm_enquiry
Missing Foundation Found
The missing outputs were not schema objects. They were governance and contract gaps:
- no dedicated Lead Foundation entry in
project-foundations.md - no Task D.5 or Task D.5.1 registration in
task-catalog.md - master-option category type registry did not include the new lead option categories, which made the seed data harder to discover and reuse from foundation settings code
- no D.5.1 implementation summary existed
Partial / Compatibility Findings
Migration history duplication risk
Lead schema work appears twice in migration history:
Compatibility status:
0020is idempotent withIF NOT EXISTS0021is a later non-idempotent generated migration for the same structural slice- D.5.1 did not create any additional migration, in line with task rules
This is recorded as a migration-history cleanup risk for future maintenance, not changed by this task.
Sequence compatibility
The foundation now includes both legacy and future-facing enquiry sequence types:
- legacy active enquiry service still generates
documentType = enquiry - lead split foundation seed also registers
crm_enquiry
That means the seed layer is ready for split-domain work, but production enquiry creation is still compatible with the older enquiry document-type contract until D.5.2+ refactors the service layer.
Active production model
Current CRM production behavior is still primarily driven by the old shared enquiry foundation:
- lead and enquiry workspace separation still relies on
crm_enquiries.pipeline_stage - no lead API, lead UI, or lead assignment flow exists yet
- dashboard and reports still rely on the pre-split data model
This is expected and remains in scope for later D.5 phases.
Changes Completed In D.5.1
- added Lead Foundation registration to
docs/standards/project-foundations.md - added Task D.5 and Task D.5.1 to
docs/standards/task-catalog.md - extended
CRM_MASTER_OPTION_CATEGORIESto include the new lead option categories insrc/features/foundation/master-options/types.ts - added this implementation note
No Duplicate Creation Performed
D.5.1 intentionally did not:
- recreate
crm_leads - recreate
crm_enquiries.lead_id - generate a new migration
- rename existing schema objects
- create lead APIs or UI
Compatibility Verification
Verification executed:
npm exec tsc --noEmit
Result:
- current Customer, Contact, Enquiry, Quotation, Dashboard, and Reports code continues to typecheck after the D.5.1 stabilization changes
Output Summary
Existing Foundation
crm_leadscrm_enquiries.lead_idADR-0018
Missing Foundation
- Lead Foundation registry entry
- Task catalog registration for D.5 and D.5.1
- master-option category contract coverage for lead option seeds
- D.5.1 implementation summary
Completed Foundation
- Lead schema and seed presence verified
- lead option categories registered in foundation type contracts
- Lead Foundation registered in the standards registry
- Task D.5 and D.5.1 registered in task history
- compatibility state documented for D.5.2 planning
Ready For Next Task
The repo is now better prepared for Task D.5.2 Lead API Foundation because:
- the foundation state is discoverable
- duplicate schema creation was avoided
- lead option categories are registered in the shared master-option contract
- current compatibility boundaries are explicitly documented