Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ model User {
ownedViews CardView[] @relation("cardOwner")
viewedCards CardView[] @relation("cardViewer")
followLogs FollowLog[]
webhookEndpoints WebhookEndpoint[]

@@unique([provider, providerId])
@@map("users")
Expand Down Expand Up @@ -124,3 +125,34 @@ model FollowLog {

@@map("follow_logs")
}

model WebhookEndpoint {
id String @id @default(uuid())
userId String @map("user_id")
url String
secret String // encrypted via encryption.ts
events String[] // e.g. ["card.viewed", "contact.saved"]
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing updatedAt needed for secret rotation auditing


user User @relation(fields: [userId], references: [id], onDelete: Cascade)
deliveries WebhookDelivery[]

@@map("webhook_endpoints")
}

model WebhookDelivery {
id String @id @default(uuid())
endpointId String @map("endpoint_id")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indexing on endpointId delivery log query will be slow.

eventType String @map("event_type")
payload Json
status String @default("pending") // "pending" | "success" | "failed"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing errorMessage String no way to surface failure reason.

responseCode Int? @map("response_code")
attempts Int @default(0)
nextRetryAt DateTime? @map("next_retry_at")
createdAt DateTime @default(now()) @map("created_at")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing updatedAt can't tell when last event fired.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing deliveredAt DateTime? no success timestamp.


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indexing for status and nextTryAt worker will scan whole thing.

endpoint WebhookEndpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade)

@@map("webhook_deliveries")
}
Loading