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
24 changes: 21 additions & 3 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ model User {
ownedTeams Team[] @relation("TeamOwner")
teamMemberships TeamMember[] @relation("TeamMember")

webhookEndpoints WebhookEndpoint[]

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.

User.webhookEndpoints references a WebhookEndpoint model that is never defined anywhere in the schema (the routes call prisma.webhookEndpoint.*). prisma generate will fail. The model needs to be added, e.g.:

model WebhookEndpoint {
  id        String   @id @default(uuid())
  userId    String   @map("user_id")
  url       String
  secret    String
  events    String[]
  isActive  Boolean  @default(true) @map("is_active")
  createdAt DateTime @default(now()) @map("created_at")

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

  @@index([userId])
  @@map("webhook_endpoints")
}

@@map("users")
}

Expand Down Expand Up @@ -183,20 +184,36 @@ model Event {
isPublic Boolean @default(true)
createdAt DateTime @default(now()) @map("created_at")
attendees EventAttendee[]

organizer User @relation(fields: [organizerId], references: [id])
}

model EventAttendee {
id String @id @default(uuid())
userId String
eventId String
joinedAt DateTime
joinedAt DateTime

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.

EventAttendee lost its relations and @@unique, and runs straight into WebhookDelivery with no separator (note the stray } on the next line). This breaks the existing EventAttendee model.

Suggested change
joinedAt DateTime
joinedAt DateTime
event Event @relation(fields: [eventId], references: [id])
user User @relation(fields: [userId], references: [id])
@@unique([userId, eventId])
}
model WebhookDelivery {

}
model WebhookDelivery {

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.

As written, this WebhookDelivery block wrongly inherited EventAttendee's event/user relations and @@unique([userId, eventId]) (lines ~210-213). It should relate to the endpoint instead:

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

id String @id @default(uuid())
endpointId String @map("endpoint_id")
eventType String @map("event_type")
payload Json
status String @default("pending") // "pending" | "success" | "failed"
responseCode Int? @map("response_code")
attempts Int @default(0)
nextRetryAt DateTime? @map("next_retry_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
errorMessage String? @map("error_message")
deliveredAt DateTime? @map("delivered_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.

errorMessage and deliveredAt are added here but deliverWebhook in webhookDispatch.ts never writes them — no error captured on failure, no timestamp on success. Either populate them in the delivery update calls or drop the columns.


event Event @relation(fields: [eventId] , references: [id])
user User @relation(fields: [userId],references: [id])

@@unique([userId, eventId])
@@index([endpointId])
@@index([status, nextRetryAt])
@@map("webhook_deliveries")
}

enum TeamRole {
Expand Down Expand Up @@ -235,4 +252,5 @@ model TeamMember{
@@unique([userId, teamId])
@@index([userId])
@@map("team_members")
}
}

Loading
Loading