diff --git a/packages/prisma/migrations/20230410234751_add_foreign_key_indexes/migration.sql b/packages/prisma/migrations/20230410234751_add_foreign_key_indexes/migration.sql new file mode 100644 index 0000000000..f02dedd07f --- /dev/null +++ b/packages/prisma/migrations/20230410234751_add_foreign_key_indexes/migration.sql @@ -0,0 +1,182 @@ +-- CreateIndex +CREATE INDEX "Account_userId_idx" ON "Account"("userId"); + +-- CreateIndex +CREATE INDEX "Account_type_idx" ON "Account"("type"); + +-- CreateIndex +CREATE INDEX "ApiKey_userId_idx" ON "ApiKey"("userId"); + +-- CreateIndex +CREATE INDEX "App_enabled_idx" ON "App"("enabled"); + +-- CreateIndex +CREATE INDEX "App_RoutingForms_Form_userId_idx" ON "App_RoutingForms_Form"("userId"); + +-- CreateIndex +CREATE INDEX "App_RoutingForms_Form_disabled_idx" ON "App_RoutingForms_Form"("disabled"); + +-- CreateIndex +CREATE INDEX "App_RoutingForms_FormResponse_formFillerId_idx" ON "App_RoutingForms_FormResponse"("formFillerId"); + +-- CreateIndex +CREATE INDEX "App_RoutingForms_FormResponse_formId_idx" ON "App_RoutingForms_FormResponse"("formId"); + +-- CreateIndex +CREATE INDEX "Attendee_email_idx" ON "Attendee"("email"); + +-- CreateIndex +CREATE INDEX "Attendee_bookingId_idx" ON "Attendee"("bookingId"); + +-- CreateIndex +CREATE INDEX "Availability_userId_idx" ON "Availability"("userId"); + +-- CreateIndex +CREATE INDEX "Booking_eventTypeId_idx" ON "Booking"("eventTypeId"); + +-- CreateIndex +CREATE INDEX "Booking_userId_idx" ON "Booking"("userId"); + +-- CreateIndex +CREATE INDEX "Booking_destinationCalendarId_idx" ON "Booking"("destinationCalendarId"); + +-- CreateIndex +CREATE INDEX "Booking_recurringEventId_idx" ON "Booking"("recurringEventId"); + +-- CreateIndex +CREATE INDEX "Booking_uid_idx" ON "Booking"("uid"); + +-- CreateIndex +CREATE INDEX "Booking_status_idx" ON "Booking"("status"); + +-- CreateIndex +CREATE INDEX "BookingReference_bookingId_idx" ON "BookingReference"("bookingId"); + +-- CreateIndex +CREATE INDEX "BookingReference_credentialId_idx" ON "BookingReference"("credentialId"); + +-- CreateIndex +CREATE INDEX "BookingReference_type_idx" ON "BookingReference"("type"); + +-- CreateIndex +CREATE INDEX "BookingReference_uid_idx" ON "BookingReference"("uid"); + +-- CreateIndex +CREATE INDEX "BookingSeat_bookingId_idx" ON "BookingSeat"("bookingId"); + +-- CreateIndex +CREATE INDEX "BookingSeat_attendeeId_idx" ON "BookingSeat"("attendeeId"); + +-- CreateIndex +CREATE INDEX "Credential_userId_idx" ON "Credential"("userId"); + +-- CreateIndex +CREATE INDEX "Credential_appId_idx" ON "Credential"("appId"); + +-- CreateIndex +CREATE INDEX "DestinationCalendar_userId_idx" ON "DestinationCalendar"("userId"); + +-- CreateIndex +CREATE INDEX "DestinationCalendar_eventTypeId_idx" ON "DestinationCalendar"("eventTypeId"); + +-- CreateIndex +CREATE INDEX "DestinationCalendar_credentialId_idx" ON "DestinationCalendar"("credentialId"); + +-- CreateIndex +CREATE INDEX "EventType_userId_idx" ON "EventType"("userId"); + +-- CreateIndex +CREATE INDEX "EventType_teamId_idx" ON "EventType"("teamId"); + +-- CreateIndex +CREATE INDEX "EventTypeCustomInput_eventTypeId_idx" ON "EventTypeCustomInput"("eventTypeId"); + +-- CreateIndex +CREATE INDEX "Feature_enabled_idx" ON "Feature"("enabled"); + +-- CreateIndex +CREATE INDEX "Feature_stale_idx" ON "Feature"("stale"); + +-- CreateIndex +CREATE INDEX "Feedback_userId_idx" ON "Feedback"("userId"); + +-- CreateIndex +CREATE INDEX "Feedback_rating_idx" ON "Feedback"("rating"); + +-- CreateIndex +CREATE INDEX "Host_userId_idx" ON "Host"("userId"); + +-- CreateIndex +CREATE INDEX "Host_eventTypeId_idx" ON "Host"("eventTypeId"); + +-- CreateIndex +CREATE INDEX "Membership_teamId_idx" ON "Membership"("teamId"); + +-- CreateIndex +CREATE INDEX "Membership_userId_idx" ON "Membership"("userId"); + +-- CreateIndex +CREATE INDEX "Payment_bookingId_idx" ON "Payment"("bookingId"); + +-- CreateIndex +CREATE INDEX "Payment_externalId_idx" ON "Payment"("externalId"); + +-- CreateIndex +CREATE INDEX "ReminderMail_referenceId_idx" ON "ReminderMail"("referenceId"); + +-- CreateIndex +CREATE INDEX "ReminderMail_reminderType_idx" ON "ReminderMail"("reminderType"); + +-- CreateIndex +CREATE INDEX "SelectedCalendar_userId_idx" ON "SelectedCalendar"("userId"); + +-- CreateIndex +CREATE INDEX "SelectedCalendar_integration_idx" ON "SelectedCalendar"("integration"); + +-- CreateIndex +CREATE INDEX "SelectedCalendar_externalId_idx" ON "SelectedCalendar"("externalId"); + +-- CreateIndex +CREATE INDEX "Session_userId_idx" ON "Session"("userId"); + +-- CreateIndex +CREATE INDEX "VerificationToken_token_idx" ON "VerificationToken"("token"); + +-- CreateIndex +CREATE INDEX "VerifiedNumber_userId_idx" ON "VerifiedNumber"("userId"); + +-- CreateIndex +CREATE INDEX "VerifiedNumber_teamId_idx" ON "VerifiedNumber"("teamId"); + +-- CreateIndex +CREATE INDEX "Workflow_userId_idx" ON "Workflow"("userId"); + +-- CreateIndex +CREATE INDEX "Workflow_teamId_idx" ON "Workflow"("teamId"); + +-- CreateIndex +CREATE INDEX "WorkflowReminder_bookingUid_idx" ON "WorkflowReminder"("bookingUid"); + +-- CreateIndex +CREATE INDEX "WorkflowReminder_workflowStepId_idx" ON "WorkflowReminder"("workflowStepId"); + +-- CreateIndex +CREATE INDEX "WorkflowStep_workflowId_idx" ON "WorkflowStep"("workflowId"); + +-- CreateIndex +CREATE INDEX "WorkflowsOnEventTypes_workflowId_idx" ON "WorkflowsOnEventTypes"("workflowId"); + +-- CreateIndex +CREATE INDEX "WorkflowsOnEventTypes_eventTypeId_idx" ON "WorkflowsOnEventTypes"("eventTypeId"); + +-- CreateIndex +CREATE INDEX "users_email_idx" ON "users"("email"); + +-- CreateIndex +CREATE INDEX "users_emailVerified_idx" ON "users"("emailVerified"); + +-- CreateIndex +CREATE INDEX "users_identityProvider_idx" ON "users"("identityProvider"); + +-- CreateIndex +CREATE INDEX "users_identityProviderId_idx" ON "users"("identityProviderId"); diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prisma index f064323445..cbcd199605 100644 --- a/packages/prisma/schema.prisma +++ b/packages/prisma/schema.prisma @@ -38,6 +38,8 @@ model Host { isFixed Boolean @default(false) @@id([userId, eventTypeId]) + @@index([userId]) + @@index([eventTypeId]) } model EventType { @@ -108,6 +110,8 @@ model EventType { @@unique([userId, slug]) @@unique([teamId, slug]) @@unique([userId, parentId]) + @@index([userId]) + @@index([teamId]) } model Credential { @@ -122,6 +126,9 @@ model Credential { appId String? destinationCalendars DestinationCalendar[] invalid Boolean? @default(false) + + @@index([userId]) + @@index([appId]) } enum IdentityProvider { @@ -141,6 +148,10 @@ model DestinationCalendar { eventTypeId Int? @unique credentialId Int? credential Credential? @relation(fields: [credentialId], references: [id], onDelete: Cascade) + + @@index([userId]) + @@index([eventTypeId]) + @@index([credentialId]) } enum UserPermissionRole { @@ -210,6 +221,10 @@ model User { verifiedNumbers VerifiedNumber[] hosts Host[] + @@index([email]) + @@index([emailVerified]) + @@index([identityProvider]) + @@index([identityProviderId]) @@map(name: "users") } @@ -251,6 +266,8 @@ model Membership { disableImpersonation Boolean @default(false) @@id([userId, teamId]) + @@index([teamId]) + @@index([userId]) } model VerificationToken { @@ -262,6 +279,7 @@ model VerificationToken { updatedAt DateTime @updatedAt @@unique([identifier, token]) + @@index([token]) } model BookingReference { @@ -278,6 +296,11 @@ model BookingReference { externalCalendarId String? deleted Boolean? credentialId Int? + + @@index([bookingId]) + @@index([credentialId]) + @@index([type]) + @@index([uid]) } model Attendee { @@ -289,6 +312,9 @@ model Attendee { booking Booking? @relation(fields: [bookingId], references: [id], onDelete: Cascade) bookingId Int? bookingSeat BookingSeat? + + @@index([email]) + @@index([bookingId]) } enum BookingStatus { @@ -336,6 +362,13 @@ model Booking { /// @zod.custom(imports.bookingMetadataSchema) metadata Json? isRecorded Boolean @default(false) + + @@index([eventTypeId]) + @@index([userId]) + @@index([destinationCalendarId]) + @@index([recurringEventId]) + @@index([uid]) + @@index([status]) } model Schedule { @@ -363,6 +396,7 @@ model Availability { Schedule Schedule? @relation(fields: [scheduleId], references: [id]) scheduleId Int? + @@index([userId]) @@index([eventTypeId]) @@index([scheduleId]) } @@ -374,6 +408,9 @@ model SelectedCalendar { externalId String @@id([userId, integration, externalId]) + @@index([userId]) + @@index([integration]) + @@index([externalId]) } enum EventTypeCustomInputType { @@ -395,6 +432,8 @@ model EventTypeCustomInput { options Json? required Boolean placeholder String @default("") + + @@index([eventTypeId]) } model ResetPasswordRequest { @@ -415,6 +454,9 @@ model ReminderMail { reminderType ReminderType elapsedMinutes Int createdAt DateTime @default(now()) + + @@index([referenceId]) + @@index([reminderType]) } model Payment { @@ -432,6 +474,9 @@ model Payment { data Json externalId String @unique paymentOption PaymentOption? @default(ON_BOOKING) + + @@index([bookingId]) + @@index([externalId]) } enum PaymentOption { @@ -486,6 +531,8 @@ model ApiKey { user User? @relation(fields: [userId], references: [id], onDelete: Cascade) app App? @relation(fields: [appId], references: [slug], onDelete: Cascade) appId String? + + @@index([userId]) } model HashedLink { @@ -512,6 +559,8 @@ model Account { user User? @relation(fields: [userId], references: [id], onDelete: Cascade) @@unique([provider, providerAccountId]) + @@index([userId]) + @@index([type]) } model Session { @@ -520,6 +569,8 @@ model Session { userId Int expires DateTime user User? @relation(fields: [userId], references: [id], onDelete: Cascade) + + @@index([userId]) } enum AppCategories { @@ -549,6 +600,8 @@ model App { Webhook Webhook[] ApiKey ApiKey[] enabled Boolean @default(false) + + @@index([enabled]) } model App_RoutingForms_Form { @@ -565,6 +618,9 @@ model App_RoutingForms_Form { disabled Boolean @default(false) /// @zod.custom(imports.RoutingFormSettings) settings Json? + + @@index([userId]) + @@index([disabled]) } model App_RoutingForms_FormResponse { @@ -576,6 +632,8 @@ model App_RoutingForms_FormResponse { createdAt DateTime @default(now()) @@unique([formFillerId, formId]) + @@index([formFillerId]) + @@index([formId]) } model Feedback { @@ -585,6 +643,9 @@ model Feedback { user User @relation(fields: [userId], references: [id], onDelete: Cascade) rating String comment String? + + @@index([userId]) + @@index([rating]) } enum WorkflowTriggerEvents { @@ -617,6 +678,8 @@ model WorkflowStep { numberRequired Boolean? sender String? numberVerificationPending Boolean @default(true) + + @@index([workflowId]) } model Workflow { @@ -631,6 +694,9 @@ model Workflow { time Int? timeUnit TimeUnit? steps WorkflowStep[] + + @@index([userId]) + @@index([teamId]) } model WorkflowsOnEventTypes { @@ -639,6 +705,9 @@ model WorkflowsOnEventTypes { workflowId Int eventType EventType @relation(fields: [eventTypeId], references: [id], onDelete: Cascade) eventTypeId Int + + @@index([workflowId]) + @@index([eventTypeId]) } model Deployment { @@ -668,6 +737,9 @@ model WorkflowReminder { workflowStepId Int? workflowStep WorkflowStep? @relation(fields: [workflowStepId], references: [id]) cancelled Boolean? + + @@index([bookingUid]) + @@index([workflowStepId]) } enum WorkflowTemplates { @@ -688,6 +760,9 @@ model BookingSeat { attendeeId Int @unique attendee Attendee @relation(fields: [attendeeId], references: [id], onDelete: Cascade) data Json? + + @@index([bookingId]) + @@index([attendeeId]) } model VerifiedNumber { @@ -697,6 +772,9 @@ model VerifiedNumber { teamId Int? team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade) phoneNumber String + + @@index([userId]) + @@index([teamId]) } model Feature { @@ -714,6 +792,9 @@ model Feature { createdAt DateTime? @default(now()) updatedAt DateTime? @default(now()) @updatedAt updatedBy Int? + + @@index([enabled]) + @@index([stale]) } enum FeatureType {