fix: added more cascading tables

This commit is contained in:
Harshith Mullapudi 2025-10-23 10:42:58 +05:30
parent af56d7016e
commit 6f1037e8e1
3 changed files with 70 additions and 35 deletions

View File

@ -25,7 +25,7 @@ model Activity {
rejectionReason String?
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId String
WebhookDeliveryLog WebhookDeliveryLog[]
@ -55,10 +55,10 @@ model Conversation {
unread Boolean @default(false)
title String?
user User @relation(fields: [userId], references: [id])
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
workspace Workspace? @relation(fields: [workspaceId], references: [id])
workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId String?
status String @default("pending") // Can be "pending", "running", "completed", "failed", "need_attention"
@ -102,7 +102,7 @@ model ConversationHistory {
context Json?
thoughts Json?
user User? @relation(fields: [userId], references: [id])
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String?
conversation Conversation @relation(fields: [conversationId], references: [id])
@ -122,7 +122,7 @@ model IngestionQueue {
type String?
workspaceId String
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
activity Activity? @relation(fields: [activityId], references: [id])
activityId String?
@ -148,10 +148,10 @@ model IngestionRule {
source String // Source/integration this rule applies to (mandatory)
isActive Boolean @default(true) // Enable/disable rule (mandatory)
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId String
user User @relation(fields: [userId], references: [id])
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
}
@ -166,11 +166,11 @@ model IntegrationAccount {
settings Json?
isActive Boolean @default(true)
integratedBy User @relation(references: [id], fields: [integratedById])
integratedBy User @relation(references: [id], fields: [integratedById], onDelete: Cascade)
integratedById String
integrationDefinition IntegrationDefinitionV2 @relation(references: [id], fields: [integrationDefinitionId])
integrationDefinitionId String
workspace Workspace @relation(references: [id], fields: [workspaceId])
workspace Workspace @relation(references: [id], fields: [workspaceId], onDelete: Cascade)
workspaceId String
Activity Activity[]
oauthIntegrationGrants OAuthIntegrationGrant[]
@ -193,7 +193,7 @@ model IntegrationDefinitionV2 {
version String?
url String?
workspace Workspace? @relation(references: [id], fields: [workspaceId])
workspace Workspace? @relation(references: [id], fields: [workspaceId], onDelete: Cascade)
workspaceId String?
IntegrationAccount IntegrationAccount[]
@ -213,7 +213,7 @@ model MCPSession {
source String
integrations String[]
workspace Workspace? @relation(references: [id], fields: [workspaceId])
workspace Workspace? @relation(references: [id], fields: [workspaceId], onDelete: Cascade)
workspaceId String?
createdAt DateTime @default(now())
@ -304,7 +304,7 @@ model OAuthClient {
workspaceId String?
// Created by user (for audit trail)
createdBy User? @relation(fields: [createdById], references: [id])
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
createdById String?
// Relations
@ -330,7 +330,7 @@ model OAuthClientInstallation {
workspaceId String
// Installation metadata
installedBy User @relation(fields: [installedById], references: [id])
installedBy User @relation(fields: [installedById], references: [id], onDelete: Cascade)
installedById String
installedAt DateTime @default(now())
uninstalledAt DateTime?
@ -410,7 +410,7 @@ model PersonalAccessToken {
/// This is used to find the token in the database
hashedToken String @unique
user User @relation(fields: [userId], references: [id])
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
revokedAt DateTime?
@ -454,13 +454,13 @@ model RecallLog {
responseTimeMs Int? // Response time in milliseconds
// Relations
user User @relation(fields: [userId], references: [id])
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
workspace Workspace? @relation(fields: [workspaceId], references: [id])
workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId String?
conversation Conversation? @relation(fields: [conversationId], references: [id])
conversation Conversation? @relation(fields: [conversationId], references: [id], onDelete: Cascade)
conversationId String?
// Metadata for additional tracking data
@ -485,7 +485,7 @@ model Space {
contextCountAtLastTrigger Int? // Context count when pattern was last triggered
// Relations
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId String
createdAt DateTime @default(now())
@ -544,7 +544,7 @@ model User {
metadata Json @default("{}")
personalAccessTokens PersonalAccessToken[]
InvitationCode InvitationCode? @relation(fields: [invitationCodeId], references: [id])
InvitationCode InvitationCode? @relation(fields: [invitationCodeId], references: [id], onDelete: Cascade)
invitationCodeId String?
Workspace Workspace?
IntegrationAccount IntegrationAccount[]
@ -584,7 +584,7 @@ model UserUsage {
searchCreditsUsed Int @default(0)
chatCreditsUsed Int @default(0)
user User @relation(fields: [userId], references: [id])
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String @unique
}
@ -596,7 +596,7 @@ model WebhookConfiguration {
eventTypes String[] // List of event types this webhook is interested in, e.g. ["activity.created"]
user User? @relation(fields: [userId], references: [id])
userId String?
workspace Workspace? @relation(fields: [workspaceId], references: [id])
workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@ -606,10 +606,10 @@ model WebhookConfiguration {
model WebhookDeliveryLog {
id String @id @default(cuid())
webhookConfiguration WebhookConfiguration @relation(fields: [webhookConfigurationId], references: [id])
webhookConfiguration WebhookConfiguration @relation(fields: [webhookConfigurationId], references: [id], onDelete: Cascade)
webhookConfigurationId String
activity Activity? @relation(fields: [activityId], references: [id])
activity Activity? @relation(fields: [activityId], references: [id], onDelete: Cascade)
activityId String?
status WebhookDeliveryStatus
@ -652,7 +652,7 @@ model Subscription {
overageAmount Float @default(0)
// Relations
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId String @unique
BillingHistory BillingHistory[]
}
@ -680,7 +680,7 @@ model BillingHistory {
stripePaymentStatus String?
// Relations
subscription Subscription @relation(fields: [subscriptionId], references: [id])
subscription Subscription @relation(fields: [subscriptionId], references: [id], onDelete: Cascade)
subscriptionId String
}
@ -697,7 +697,7 @@ model Workspace {
integrations String[]
userId String? @unique
user User? @relation(fields: [userId], references: [id])
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
IngestionQueue IngestionQueue[]
IntegrationAccount IntegrationAccount[]
IntegrationDefinitionV2 IntegrationDefinitionV2[]

View File

@ -0,0 +1,35 @@
-- DropForeignKey
ALTER TABLE "BillingHistory" DROP CONSTRAINT "BillingHistory_subscriptionId_fkey";
-- DropForeignKey
ALTER TABLE "PersonalAccessToken" DROP CONSTRAINT "PersonalAccessToken_userId_fkey";
-- DropForeignKey
ALTER TABLE "RecallLog" DROP CONSTRAINT "RecallLog_conversationId_fkey";
-- DropForeignKey
ALTER TABLE "User" DROP CONSTRAINT "User_invitationCodeId_fkey";
-- DropForeignKey
ALTER TABLE "WebhookDeliveryLog" DROP CONSTRAINT "WebhookDeliveryLog_activityId_fkey";
-- DropForeignKey
ALTER TABLE "WebhookDeliveryLog" DROP CONSTRAINT "WebhookDeliveryLog_webhookConfigurationId_fkey";
-- AddForeignKey
ALTER TABLE "PersonalAccessToken" ADD CONSTRAINT "PersonalAccessToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "RecallLog" ADD CONSTRAINT "RecallLog_conversationId_fkey" FOREIGN KEY ("conversationId") REFERENCES "Conversation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_invitationCodeId_fkey" FOREIGN KEY ("invitationCodeId") REFERENCES "InvitationCode"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "WebhookDeliveryLog" ADD CONSTRAINT "WebhookDeliveryLog_webhookConfigurationId_fkey" FOREIGN KEY ("webhookConfigurationId") REFERENCES "WebhookConfiguration"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "WebhookDeliveryLog" ADD CONSTRAINT "WebhookDeliveryLog_activityId_fkey" FOREIGN KEY ("activityId") REFERENCES "Activity"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "BillingHistory" ADD CONSTRAINT "BillingHistory_subscriptionId_fkey" FOREIGN KEY ("subscriptionId") REFERENCES "Subscription"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -410,7 +410,7 @@ model PersonalAccessToken {
/// This is used to find the token in the database
hashedToken String @unique
user User @relation(fields: [userId], references: [id])
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
revokedAt DateTime?
@ -460,7 +460,7 @@ model RecallLog {
workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId String?
conversation Conversation? @relation(fields: [conversationId], references: [id])
conversation Conversation? @relation(fields: [conversationId], references: [id], onDelete: Cascade)
conversationId String?
// Metadata for additional tracking data
@ -488,9 +488,9 @@ model Space {
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
SpacePattern SpacePattern[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
SpacePattern SpacePattern[]
}
model SpacePattern {
@ -544,7 +544,7 @@ model User {
metadata Json @default("{}")
personalAccessTokens PersonalAccessToken[]
InvitationCode InvitationCode? @relation(fields: [invitationCodeId], references: [id])
InvitationCode InvitationCode? @relation(fields: [invitationCodeId], references: [id], onDelete: Cascade)
invitationCodeId String?
Workspace Workspace?
IntegrationAccount IntegrationAccount[]
@ -606,10 +606,10 @@ model WebhookConfiguration {
model WebhookDeliveryLog {
id String @id @default(cuid())
webhookConfiguration WebhookConfiguration @relation(fields: [webhookConfigurationId], references: [id])
webhookConfiguration WebhookConfiguration @relation(fields: [webhookConfigurationId], references: [id], onDelete: Cascade)
webhookConfigurationId String
activity Activity? @relation(fields: [activityId], references: [id])
activity Activity? @relation(fields: [activityId], references: [id], onDelete: Cascade)
activityId String?
status WebhookDeliveryStatus
@ -680,7 +680,7 @@ model BillingHistory {
stripePaymentStatus String?
// Relations
subscription Subscription @relation(fields: [subscriptionId], references: [id])
subscription Subscription @relation(fields: [subscriptionId], references: [id], onDelete: Cascade)
subscriptionId String
}