Files
HiveGrid-Wireframes/hivegrid-cloud/prisma/schema/entityLinks.prisma
T

46 lines
1.5 KiB
Plaintext

// P4 EntityLink (AK-P4b) — Gate W1 deliverable.
//
// AD-21: one self-contained schema file per module. `tenantId` /
// `createdByUserId` are intentionally BARE String scalars (no `@relation`).
//
// Generic, fully polymorphic link between any two entities. Both sides
// (source + target) are polymorphic so every later module docks onto this one
// table instead of building its own link table. Reusable cross-cutting
// primitive: R-P6 ff. attach Task<->CRM, File<->CRM (beyond FileEntityLink),
// and any future relation here.
//
// Note: `FileEntityLink` (files.prisma) predates this table and stays as-is for
// the file-specific upload flow; new generic links use `EntityLink`.
enum LinkableEntityType {
contact
company
lead
deal
project
task
file
user
order
appointment
form_submission
}
/// A directed, role-labelled link from one entity to another, scoped per tenant.
/// Idempotent on the unique tuple (upsert in entityLinkService).
model EntityLink {
id String @id @default(cuid())
createdAt DateTime @default(now())
tenantId String
createdByUserId String
sourceType LinkableEntityType
sourceId String
targetType LinkableEntityType
targetId String
linkRole String? // optional role label (e.g. "depends-on", "reference")
@@unique([tenantId, sourceType, sourceId, targetType, targetId])
@@index([tenantId, targetType, targetId])
@@index([tenantId, sourceType, sourceId])
}