KI-AGENT: Mailantworten und Entitätsverknüpfungen ergänzen

This commit is contained in:
2026-09-07 19:00:08 +02:00
parent 4e4466ff11
commit f3384cfc74
10 changed files with 774 additions and 30 deletions

View File

@@ -155,6 +155,39 @@ export const emailAttachments = pgTable(
}),
)
export const emailEntityLinks = pgTable(
"email_entity_links",
{
id: uuid("id").primaryKey().defaultRandom(),
tenantId: bigint("tenant_id", { mode: "number" })
.notNull()
.references(() => tenants.id, { onDelete: "cascade", onUpdate: "cascade" }),
messageId: uuid("message_id")
.notNull()
.references(() => emailMessages.id, { onDelete: "cascade", onUpdate: "cascade" }),
entityType: text("entity_type").notNull(),
entityId: bigint("entity_id", { mode: "number" }).notNull(),
linkedBy: uuid("linked_by")
.references(() => authUsers.id, { onDelete: "set null", onUpdate: "cascade" }),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => ({
messageEntityKey: uniqueIndex("email_entity_links_message_entity_key")
.on(table.messageId, table.entityType, table.entityId),
entityIdx: index("email_entity_links_entity_idx")
.on(table.tenantId, table.entityType, table.entityId),
messageIdx: index("email_entity_links_message_idx")
.on(table.messageId),
}),
)
export const emailSyncState = pgTable(
"email_sync_state",
{
@@ -204,5 +237,7 @@ export type EmailMessageBody = typeof emailMessageBodies.$inferSelect
export type NewEmailMessageBody = typeof emailMessageBodies.$inferInsert
export type EmailAttachment = typeof emailAttachments.$inferSelect
export type NewEmailAttachment = typeof emailAttachments.$inferInsert
export type EmailEntityLink = typeof emailEntityLinks.$inferSelect
export type NewEmailEntityLink = typeof emailEntityLinks.$inferInsert
export type EmailSyncState = typeof emailSyncState.$inferSelect
export type NewEmailSyncState = typeof emailSyncState.$inferInsert