task-ep.1.5

This commit is contained in:
phaichayon
2026-07-13 15:03:17 +07:00
parent bba4c8d97d
commit 2bc8dd184c
19 changed files with 9722 additions and 5 deletions

View File

@@ -625,6 +625,57 @@ export const projectionHealthSnapshots = pgTable(
})
);
export const crmTimelineProjection = pgTable(
'crm_timeline_projection',
{
id: text('id').primaryKey(),
organizationId: text('organization_id').notNull(),
branchId: text('branch_id'),
customerId: text('customer_id'),
leadId: text('lead_id'),
opportunityId: text('opportunity_id'),
quotationId: text('quotation_id'),
activityId: text('activity_id'),
eventId: text('event_id').notNull(),
entityType: text('entity_type').notNull(),
entityId: text('entity_id').notNull(),
timelineType: text('timeline_type').notNull(),
timelineCategory: text('timeline_category').notNull(),
occurredAt: timestamp('occurred_at', { withTimezone: true }).notNull(),
actorId: text('actor_id'),
actorDisplay: text('actor_display'),
title: text('title').notNull(),
summary: text('summary'),
icon: text('icon').notNull(),
color: text('color').notNull(),
priority: text('priority').default('normal').notNull(),
visibility: jsonb('visibility').notNull(),
metadata: jsonb('metadata'),
sourceEvent: jsonb('source_event').notNull(),
sourceProjectionVersion: integer('source_projection_version').default(1).notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull()
},
(table) => ({
eventVersionIdx: uniqueIndex('crm_timeline_projection_event_version_idx').on(
table.eventId,
table.sourceProjectionVersion
),
organizationOccurredIdx: index('crm_timeline_projection_org_occurred_idx').on(
table.organizationId,
table.occurredAt
),
customerOccurredIdx: index('crm_timeline_projection_customer_occurred_idx').on(
table.organizationId,
table.customerId,
table.occurredAt
),
activityEventIdx: index('crm_timeline_projection_activity_event_idx').on(
table.activityId,
table.eventId
)
})
);
export const crmCustomers = pgTable(
'crm_customers',
{