diff --git a/apps/webapp/app/database-types.ts b/apps/webapp/app/database-types.ts index 1fcd822c07..b6d47cd9ac 100644 --- a/apps/webapp/app/database-types.ts +++ b/apps/webapp/app/database-types.ts @@ -7,7 +7,6 @@ import type { BatchTaskRunItemStatus as BatchTaskRunItemStatusType, TaskRunAttemptStatus as TaskRunAttemptStatusType, TaskRunStatus as TaskRunStatusType, - JobRunStatus as JobRunStatusType, RuntimeEnvironmentType as RuntimeEnvironmentTypeType, } from "@trigger.dev/database"; @@ -46,24 +45,6 @@ export const TaskRunStatus = { TIMED_OUT: "TIMED_OUT", } as const satisfies Record; -export const JobRunStatus = { - PENDING: "PENDING", - QUEUED: "QUEUED", - WAITING_ON_CONNECTIONS: "WAITING_ON_CONNECTIONS", - PREPROCESSING: "PREPROCESSING", - STARTED: "STARTED", - EXECUTING: "EXECUTING", - WAITING_TO_CONTINUE: "WAITING_TO_CONTINUE", - WAITING_TO_EXECUTE: "WAITING_TO_EXECUTE", - SUCCESS: "SUCCESS", - FAILURE: "FAILURE", - TIMED_OUT: "TIMED_OUT", - ABORTED: "ABORTED", - CANCELED: "CANCELED", - UNRESOLVED_AUTH: "UNRESOLVED_AUTH", - INVALID_PAYLOAD: "INVALID_PAYLOAD", -} as const satisfies Record; - export const RuntimeEnvironmentType = { PRODUCTION: "PRODUCTION", STAGING: "STAGING", diff --git a/apps/webapp/app/services/platform.v3.server.ts b/apps/webapp/app/services/platform.v3.server.ts index f42f719188..dbc9acc265 100644 --- a/apps/webapp/app/services/platform.v3.server.ts +++ b/apps/webapp/app/services/platform.v3.server.ts @@ -193,15 +193,6 @@ export async function getCurrentPlan(orgId: string) { firstDayOfNextMonth.setUTCMonth(firstDayOfNextMonth.getUTCMonth() + 1); firstDayOfNextMonth.setUTCHours(0, 0, 0, 0); - const currentRunCount = await $replica.jobRun.count({ - where: { - organizationId: orgId, - createdAt: { - gte: firstDayOfMonth, - }, - }, - }); - if (!result.success) { logger.error("Error getting current plan", { orgId, error: result.error }); return undefined; @@ -212,11 +203,6 @@ export async function getCurrentPlan(orgId: string) { const periodRemainingDuration = periodEnd.getTime() - new Date().getTime(); const usage = { - currentRunCount, - runCountCap: result.subscription?.plan.runs?.freeAllowance, - exceededRunCount: result.subscription?.plan.runs?.freeAllowance - ? currentRunCount > result.subscription?.plan.runs?.freeAllowance - : false, periodStart, periodEnd, periodRemainingDuration, diff --git a/apps/webapp/app/services/telemetry.server.ts b/apps/webapp/app/services/telemetry.server.ts index 5d184a8b1f..98ca11ed90 100644 --- a/apps/webapp/app/services/telemetry.server.ts +++ b/apps/webapp/app/services/telemetry.server.ts @@ -1,4 +1,3 @@ -import { Job } from "@trigger.dev/database"; import { PostHog } from "posthog-node"; import { env } from "~/env.server"; import { MatchedOrganization } from "~/hooks/useOrganizations"; @@ -145,7 +144,6 @@ class Telemetry { }, }); }, - deletedJob: ({ job }: { job: Job }) => {}, }; #capture(event: CaptureEvent) { diff --git a/internal-packages/database/prisma/migrations/20250526092407_remove_v2_tables_round_1/migration.sql b/internal-packages/database/prisma/migrations/20250526092407_remove_v2_tables_round_1/migration.sql new file mode 100644 index 0000000000..ef297ab4ce --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526092407_remove_v2_tables_round_1/migration.sql @@ -0,0 +1,103 @@ +/* + Warnings: + + - You are about to drop the `JobCounter` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `WebhookDeliveryCounter` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `ApiIntegrationVote` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `ConnectionAttempt` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `DeferredScheduledEventService` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `DynamicTriggerRegistration` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `EndpointIndex` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `EventExample` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `HttpSourceRequestDelivery` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `JobAlias` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `JobIntegration` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `JobRunAutoYieldExecution` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `JobRunStatusRecord` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `JobRunSubscription` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `KeyValueItem` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `MissingConnection` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `TaskAttempt` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `TriggerSourceOption` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `WebhookRequestDelivery` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `_JobRunToMissingConnection` table. If the table is not empty, all the data it contains will be lost. + +*/ + +-- DropTable +DROP TABLE IF EXISTS "JobCounter"; + +-- DropTable +DROP TABLE IF EXISTS "WebhookDeliveryCounter"; + +-- DropTable +DROP TABLE IF EXISTS "ApiIntegrationVote"; + +-- DropTable +DROP TABLE IF EXISTS "ConnectionAttempt"; + +-- DropTable +DROP TABLE IF EXISTS "DeferredScheduledEventService"; + +-- DropTable +DROP TABLE IF EXISTS "DynamicTriggerRegistration"; + +-- DropTable +DROP TABLE IF EXISTS "EndpointIndex"; + +-- DropTable +DROP TABLE IF EXISTS "EventExample"; + +-- DropTable +DROP TABLE IF EXISTS "HttpSourceRequestDelivery"; + +-- DropTable +DROP TABLE IF EXISTS "JobAlias"; + +-- DropTable +DROP TABLE IF EXISTS "JobIntegration"; + +-- DropTable +DROP TABLE IF EXISTS "JobRunAutoYieldExecution"; + +-- DropTable +DROP TABLE IF EXISTS "JobRunStatusRecord"; + +-- DropTable +DROP TABLE IF EXISTS "JobRunSubscription"; + +-- DropTable +DROP TABLE IF EXISTS "KeyValueItem"; + +-- DropTable +DROP TABLE IF EXISTS "MissingConnection" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "TaskAttempt"; + +-- DropTable +DROP TABLE IF EXISTS "TriggerSourceOption"; + +-- DropTable +DROP TABLE IF EXISTS "WebhookRequestDelivery"; + +-- DropTable +DROP TABLE IF EXISTS "_JobRunToMissingConnection"; + +-- DropEnum +DROP TYPE IF EXISTS "EndpointIndexSource"; + +-- DropEnum +DROP TYPE IF EXISTS "EndpointIndexStatus"; + +-- DropEnum +DROP TYPE IF EXISTS "JobRunSubscriptionEvents"; + +-- DropEnum +DROP TYPE IF EXISTS "JobRunSubscriptionRecipientMethod"; + +-- DropEnum +DROP TYPE IF EXISTS "JobRunSubscriptionStatus"; + +-- DropEnum +DROP TYPE IF EXISTS "TaskAttemptStatus"; diff --git a/internal-packages/database/prisma/migrations/20250526093738_remove_v2_round_2/migration.sql b/internal-packages/database/prisma/migrations/20250526093738_remove_v2_round_2/migration.sql new file mode 100644 index 0000000000..1722c38cc6 --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526093738_remove_v2_round_2/migration.sql @@ -0,0 +1,16 @@ +/* + Warnings: + + - You are about to drop the `JobRunExecution` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `ScheduleSource` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `WebhookEnvironment` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +DROP TABLE IF EXISTS "JobRunExecution" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "ScheduleSource" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "WebhookEnvironment" CASCADE; diff --git a/internal-packages/database/prisma/migrations/20250526094044_remove_v2_trigger_http_endpoint_environment/migration.sql b/internal-packages/database/prisma/migrations/20250526094044_remove_v2_trigger_http_endpoint_environment/migration.sql new file mode 100644 index 0000000000..32c8e589df --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526094044_remove_v2_trigger_http_endpoint_environment/migration.sql @@ -0,0 +1,12 @@ +/* + Warnings: + + - You are about to drop the column `httpEndpointEnvironmentId` on the `EventRecord` table. All the data in the column will be lost. + - You are about to drop the `TriggerHttpEndpointEnvironment` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- AlterTable +ALTER TABLE "EventRecord" DROP COLUMN IF EXISTS "httpEndpointEnvironmentId" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "TriggerHttpEndpointEnvironment" CASCADE; diff --git a/internal-packages/database/prisma/migrations/20250526094442_remove_v2_round_3/migration.sql b/internal-packages/database/prisma/migrations/20250526094442_remove_v2_round_3/migration.sql new file mode 100644 index 0000000000..354fcc585e --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526094442_remove_v2_round_3/migration.sql @@ -0,0 +1,12 @@ +/* + Warnings: + + - You are about to drop the `Task` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `Webhook` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +DROP TABLE IF EXISTS "Task" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "Webhook" CASCADE; diff --git a/internal-packages/database/prisma/migrations/20250526094729_remove_v2_round_4/migration.sql b/internal-packages/database/prisma/migrations/20250526094729_remove_v2_round_4/migration.sql new file mode 100644 index 0000000000..d2ce2d6a0f --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526094729_remove_v2_round_4/migration.sql @@ -0,0 +1,13 @@ +/* + Warnings: + + - You are about to drop the `RunConnection` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `TriggerSource` table. If the table is not empty, all the data it contains will be lost. + +*/ + +-- DropTable +DROP TABLE IF EXISTS "RunConnection" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "TriggerSource" CASCADE; diff --git a/internal-packages/database/prisma/migrations/20250526095040_remove_v2_round_5/migration.sql b/internal-packages/database/prisma/migrations/20250526095040_remove_v2_round_5/migration.sql new file mode 100644 index 0000000000..1c8b766202 --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526095040_remove_v2_round_5/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - You are about to drop the `IntegrationConnection` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +DROP TABLE IF EXISTS "IntegrationConnection" CASCADE; diff --git a/internal-packages/database/prisma/migrations/20250526095444_remove_v2_round_6/migration.sql b/internal-packages/database/prisma/migrations/20250526095444_remove_v2_round_6/migration.sql new file mode 100644 index 0000000000..fba331aba9 --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526095444_remove_v2_round_6/migration.sql @@ -0,0 +1,24 @@ +/* + Warnings: + + - You are about to drop the `DynamicTrigger` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `EventDispatcher` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `EventRecord` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `JobRun` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `_DynamicTriggerToJob` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +DROP TABLE IF EXISTS "DynamicTrigger" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "EventDispatcher" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "EventRecord" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "JobRun" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "_DynamicTriggerToJob" CASCADE; diff --git a/internal-packages/database/prisma/migrations/20250526095826_remove_v2_round_7/migration.sql b/internal-packages/database/prisma/migrations/20250526095826_remove_v2_round_7/migration.sql new file mode 100644 index 0000000000..df7e5dced5 --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526095826_remove_v2_round_7/migration.sql @@ -0,0 +1,12 @@ +/* + Warnings: + + - You are about to drop the `JobVersion` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `TriggerHttpEndpoint` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +DROP TABLE IF EXISTS "JobVersion" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "TriggerHttpEndpoint" CASCADE; diff --git a/internal-packages/database/prisma/migrations/20250526100059_remove_v2_round_8/migration.sql b/internal-packages/database/prisma/migrations/20250526100059_remove_v2_round_8/migration.sql new file mode 100644 index 0000000000..ef8897298e --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526100059_remove_v2_round_8/migration.sql @@ -0,0 +1,20 @@ +/* + Warnings: + + - You are about to drop the `ConcurrencyLimitGroup` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `Endpoint` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `Job` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `JobQueue` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +DROP TABLE IF EXISTS "ConcurrencyLimitGroup" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "Endpoint" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "Job" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "JobQueue" CASCADE; diff --git a/internal-packages/database/prisma/migrations/20250526100402_remove_v2_round_9/migration.sql b/internal-packages/database/prisma/migrations/20250526100402_remove_v2_round_9/migration.sql new file mode 100644 index 0000000000..7d333191d3 --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526100402_remove_v2_round_9/migration.sql @@ -0,0 +1,20 @@ +/* + Warnings: + + - You are about to drop the `ExternalAccount` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `Integration` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `IntegrationAuthMethod` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `IntegrationDefinition` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +DROP TABLE IF EXISTS "ExternalAccount" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "Integration" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "IntegrationAuthMethod" CASCADE; + +-- DropTable +DROP TABLE IF EXISTS "IntegrationDefinition" CASCADE; diff --git a/internal-packages/database/prisma/migrations/20250526100607_remove_v2_round_10/migration.sql b/internal-packages/database/prisma/migrations/20250526100607_remove_v2_round_10/migration.sql new file mode 100644 index 0000000000..c2e13ac864 --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250526100607_remove_v2_round_10/migration.sql @@ -0,0 +1,38 @@ +-- DropEnum +DROP TYPE IF EXISTS "ConnectionType"; + +-- DropEnum +DROP TYPE IF EXISTS "DynamicTriggerType"; + +-- DropEnum +DROP TYPE IF EXISTS "IntegrationAuthSource"; + +-- DropEnum +DROP TYPE IF EXISTS "IntegrationSetupStatus"; + +-- DropEnum +DROP TYPE IF EXISTS "JobRunExecutionReason"; + +-- DropEnum +DROP TYPE IF EXISTS "JobRunExecutionStatus"; + +-- DropEnum +DROP TYPE IF EXISTS "JobRunStatus"; + +-- DropEnum +DROP TYPE IF EXISTS "JobStartPosition"; + +-- DropEnum +DROP TYPE IF EXISTS "JobVersionStatus"; + +-- DropEnum +DROP TYPE IF EXISTS "PayloadType"; + +-- DropEnum +DROP TYPE IF EXISTS "TaskChildExecutionMode"; + +-- DropEnum +DROP TYPE IF EXISTS "TaskStatus"; + +-- DropEnum +DROP TYPE IF EXISTS "TriggerChannel"; diff --git a/internal-packages/database/prisma/schema.prisma b/internal-packages/database/prisma/schema.prisma index 934a72a737..423ed1056b 100644 --- a/internal-packages/database/prisma/schema.prisma +++ b/internal-packages/database/prisma/schema.prisma @@ -46,9 +46,6 @@ model User { orgMemberships OrgMember[] sentInvites OrgMemberInvite[] - /// @deprecated - apiVotes ApiIntegrationVote[] - invitationCode InvitationCode? @relation(fields: [invitationCodeId], references: [id]) invitationCodeId String? personalAccessTokens PersonalAccessToken[] @@ -145,12 +142,6 @@ model Organization { hasRequestedV3 Boolean @default(false) environments RuntimeEnvironment[] - connections IntegrationConnection[] - endpoints Endpoint[] - jobs Job[] - jobVersions JobVersion[] - events EventRecord[] - jobRuns JobRun[] apiRateLimiterConfig Json? realtimeRateLimiterConfig Json? @@ -158,179 +149,12 @@ model Organization { projects Project[] members OrgMember[] invites OrgMemberInvite[] - externalAccounts ExternalAccount[] - integrations Integration[] - sources TriggerSource[] organizationIntegrations OrganizationIntegration[] workerGroups WorkerInstanceGroup[] workerInstances WorkerInstance[] executionSnapshots TaskRunExecutionSnapshot[] } -model ExternalAccount { - id String @id @default(cuid()) - identifier String - metadata Json? - - organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - organizationId String - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - connections IntegrationConnection[] - events EventRecord[] - runs JobRun[] - schedules ScheduleSource[] - triggerSources TriggerSource[] - missingConnections MissingConnection[] - EventDispatcher EventDispatcher[] - - @@unique([environmentId, identifier]) -} - -// This is a "global" table that store all the integration methods for all the integrations across all orgs -model IntegrationAuthMethod { - id String @id @default(cuid()) - key String - - name String - description String - type String - - client Json? - config Json? - scopes Json? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - integrations Integration[] - - definition IntegrationDefinition @relation(fields: [definitionId], references: [id], onDelete: Cascade, onUpdate: Cascade) - definitionId String - - help Json? - - @@unique([definitionId, key]) -} - -model IntegrationDefinition { - id String @id - name String - instructions String? - description String? - icon String? - packageName String @default("") - - authMethods IntegrationAuthMethod[] - Integration Integration[] -} - -model Integration { - id String @id @default(cuid()) - - slug String - - title String? - description String? - - setupStatus IntegrationSetupStatus @default(COMPLETE) - authSource IntegrationAuthSource @default(HOSTED) - - definition IntegrationDefinition @relation(fields: [definitionId], references: [id], onDelete: Cascade, onUpdate: Cascade) - definitionId String - - authMethod IntegrationAuthMethod? @relation(fields: [authMethodId], references: [id], onDelete: Cascade, onUpdate: Cascade) - authMethodId String? - - connectionType ConnectionType @default(DEVELOPER) - - scopes String[] - - customClientReference SecretReference? @relation(fields: [customClientReferenceId], references: [id], onDelete: Cascade, onUpdate: Cascade) - customClientReferenceId String? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - organizationId String - - attempts ConnectionAttempt[] - connections IntegrationConnection[] - jobIntegrations JobIntegration[] - sources TriggerSource[] - webhooks Webhook[] - missingConnections MissingConnection[] - RunConnection RunConnection[] - - @@unique([organizationId, slug]) -} - -enum IntegrationAuthSource { - HOSTED - LOCAL - RESOLVER -} - -enum IntegrationSetupStatus { - MISSING_FIELDS - COMPLETE -} - -model IntegrationConnection { - id String @id @default(cuid()) - - connectionType ConnectionType @default(DEVELOPER) - - expiresAt DateTime? - metadata Json - scopes String[] - - dataReference SecretReference @relation(fields: [dataReferenceId], references: [id], onDelete: Cascade, onUpdate: Cascade) - dataReferenceId String - - integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - integrationId String - - organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - organizationId String - - externalAccount ExternalAccount? @relation(fields: [externalAccountId], references: [id], onDelete: Cascade, onUpdate: Cascade) - externalAccountId String? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - /// If enabled is false, OAuth refreshing will not be attempted - enabled Boolean @default(true) - - runConnections RunConnection[] -} - -enum ConnectionType { - EXTERNAL - DEVELOPER -} - -model ConnectionAttempt { - id String @id @default(cuid()) - - securityCode String? - - redirectTo String @default("/") - - createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) @updatedAt - - integration Integration @relation(fields: [integrationId], references: [id]) - integrationId String -} - model OrgMember { id String @id @default(cuid()) @@ -417,26 +241,8 @@ model RuntimeEnvironment { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt - /// @deprecated (v2) - tunnelId String? - endpoints Endpoint[] - jobVersions JobVersion[] - events EventRecord[] - jobRuns JobRun[] - requestDeliveries HttpSourceRequestDelivery[] - jobAliases JobAlias[] - JobQueue JobQueue[] - sources TriggerSource[] - eventDispatchers EventDispatcher[] - scheduleSources ScheduleSource[] - ExternalAccount ExternalAccount[] - httpEndpointEnvironments TriggerHttpEndpointEnvironment[] - concurrencyLimitGroups ConcurrencyLimitGroup[] - keyValueItems KeyValueItem[] - webhookEnvironments WebhookEnvironment[] - webhookRequestDeliveries WebhookRequestDelivery[] - - /// v3 + tunnelId String? + backgroundWorkers BackgroundWorker[] backgroundWorkerTasks BackgroundWorkerTask[] taskRuns TaskRun[] @@ -500,14 +306,6 @@ model Project { defaultWorkerGroupId String? environments RuntimeEnvironment[] - endpoints Endpoint[] - jobs Job[] - jobVersion JobVersion[] - events EventRecord[] - runs JobRun[] - sources TriggerSource[] - httpEndpoints TriggerHttpEndpoint[] - webhooks Webhook[] backgroundWorkers BackgroundWorker[] backgroundWorkerTasks BackgroundWorkerTask[] taskRuns TaskRun[] @@ -535,1215 +333,181 @@ enum ProjectVersion { V3 } -model Endpoint { - id String @id @default(cuid()) - slug String - url String? - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - organizationId String - - project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) - projectId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - indexingHookIdentifier String? - version String @default("unknown") - sdkVersion String @default("unknown") - - runChunkExecutionLimit Int @default(60000) - startTaskThreshold Int @default(750) - beforeExecuteTaskThreshold Int @default(1500) - beforeCompleteTaskThreshold Int @default(750) - afterCompleteTaskThreshold Int @default(750) +model SecretReference { + id String @id @default(cuid()) + key String @unique + provider SecretStoreProvider @default(DATABASE) - jobVersions JobVersion[] - jobRuns JobRun[] - httpRequestDeliveries HttpSourceRequestDelivery[] - webhookRequestDeliveries WebhookRequestDelivery[] - dynamictriggers DynamicTrigger[] - sources TriggerSource[] - indexings EndpointIndex[] - httpEndpointEnvironments TriggerHttpEndpointEnvironment[] - webhookEnvironments WebhookEnvironment[] + environmentVariableValues EnvironmentVariableValue[] - @@unique([environmentId, slug]) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + OrganizationIntegration OrganizationIntegration[] } -model EndpointIndex { - id String @id @default(cuid()) +enum SecretStoreProvider { + DATABASE + AWS_PARAM_STORE +} - endpoint Endpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - endpointId String +model SecretStore { + key String @unique + value Json + version String @default("1") createdAt DateTime @default(now()) updatedAt DateTime @updatedAt - source EndpointIndexSource @default(MANUAL) - sourceData Json? - reason String? - status EndpointIndexStatus @default(PENDING) - - data Json? - stats Json? - error Json? + @@index([key(ops: raw("text_pattern_ops"))], type: BTree) } -enum EndpointIndexSource { - MANUAL - API - INTERNAL - HOOK -} +model DataMigration { + id String @id @default(cuid()) + name String @unique -enum EndpointIndexStatus { - PENDING - STARTED - SUCCESS - FAILURE + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + completedAt DateTime? } -model Job { - id String @id @default(cuid()) - slug String - title String - internal Boolean @default(false) +// ==================================================== +// v3 Models +// ==================================================== +model BackgroundWorker { + id String @id @default(cuid()) - organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - organizationId String + friendlyId String @unique + + engine RunEngineVersion @default(V1) + + contentHash String + sdkVersion String @default("unknown") + cliVersion String @default("unknown") project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) projectId String - versions JobVersion[] - runs JobRun[] - integrations JobIntegration[] - aliases JobAlias[] - dynamicTriggers DynamicTrigger[] + runtimeEnvironment RuntimeEnvironment @relation(fields: [runtimeEnvironmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) + runtimeEnvironmentId String + + version String + metadata Json createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) @updatedAt + updatedAt DateTime @updatedAt - deletedAt DateTime? + tasks BackgroundWorkerTask[] + attempts TaskRunAttempt[] + lockedRuns TaskRun[] + files BackgroundWorkerFile[] + queues TaskQueue[] - @@unique([projectId, slug]) -} + deployment WorkerDeployment? -model JobVersion { - id String @id @default(cuid()) - version String - eventSpecification Json + workerGroup WorkerInstanceGroup? @relation(fields: [workerGroupId], references: [id], onDelete: SetNull, onUpdate: Cascade) + workerGroupId String? - properties Json? - triggerLink String? - triggerHelp Json? + supportsLazyAttempts Boolean @default(false) - job Job @relation(fields: [jobId], references: [id], onDelete: Cascade, onUpdate: Cascade) - jobId String + @@unique([projectId, runtimeEnvironmentId, version]) + @@index([runtimeEnvironmentId]) + // Get the latest worker for a given environment + @@index([runtimeEnvironmentId, createdAt(sort: Desc)]) +} - endpoint Endpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - endpointId String +model BackgroundWorkerFile { + id String @id @default(cuid()) - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String + friendlyId String @unique - organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - organizationId String + filePath String + contentHash String + contents Bytes project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) projectId String - queue JobQueue? @relation(fields: [queueId], references: [id]) - queueId String? - - startPosition JobStartPosition @default(INITIAL) - preprocessRuns Boolean @default(false) + backgroundWorkers BackgroundWorker[] - concurrencyLimit Int? - concurrencyLimitGroup ConcurrencyLimitGroup? @relation(fields: [concurrencyLimitGroupId], references: [id]) - concurrencyLimitGroupId String? + tasks BackgroundWorkerTask[] createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - runs JobRun[] - integrations JobIntegration[] - aliases JobAlias[] - examples EventExample[] - dynamicTriggers DynamicTrigger[] - triggerSources TriggerSource[] - status JobVersionStatus @default(ACTIVE) - - @@unique([jobId, version, environmentId]) -} - -enum JobVersionStatus { - ACTIVE - DISABLED + @@unique([projectId, contentHash]) } -model EventExample { - id String @id @default(cuid()) - +model BackgroundWorkerTask { + id String @id @default(cuid()) slug String - name String - icon String? - payload Json? + description String? - jobVersion JobVersion @relation(fields: [jobVersionId], references: [id], onDelete: Cascade, onUpdate: Cascade) - jobVersionId String + friendlyId String @unique - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + filePath String + exportName String? - @@unique([slug, jobVersionId]) -} + worker BackgroundWorker @relation(fields: [workerId], references: [id], onDelete: Cascade, onUpdate: Cascade) + workerId String -model ConcurrencyLimitGroup { - id String @id @default(cuid()) - name String + project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) + projectId String - concurrencyLimit Int + file BackgroundWorkerFile? @relation(fields: [fileId], references: [id], onDelete: Cascade, onUpdate: Cascade) + fileId String? - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String + runtimeEnvironment RuntimeEnvironment @relation(fields: [runtimeEnvironmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) + runtimeEnvironmentId String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt - jobVersion JobVersion[] - - @@unique([environmentId, name]) -} - -model JobQueue { - id String @id @default(cuid()) - name String + attempts TaskRunAttempt[] + runs TaskRun[] - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String + queueConfig Json? + retryConfig Json? + machineConfig Json? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + queueId String? + queue TaskQueue? @relation(fields: [queueId], references: [id], onDelete: SetNull, onUpdate: Cascade) - jobCount Int @default(0) - maxJobs Int @default(100) + maxDurationInSeconds Int? - runs JobRun[] - jobVersion JobVersion[] + triggerSource TaskTriggerSource @default(STANDARD) - @@unique([environmentId, name]) + @@unique([workerId, slug]) + // Quick lookup of task identifiers + @@index([projectId, slug]) + @@index([runtimeEnvironmentId, projectId]) } -model JobAlias { - id String @id @default(cuid()) - name String @default("latest") - value String +enum TaskTriggerSource { + STANDARD + SCHEDULED +} - version JobVersion @relation(fields: [versionId], references: [id], onDelete: Cascade, onUpdate: Cascade) - versionId String +model TaskRun { + id String @id @default(cuid()) - job Job @relation(fields: [jobId], references: [id], onDelete: Cascade, onUpdate: Cascade) - jobId String + number Int @default(0) + friendlyId String @unique - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String + engine RunEngineVersion @default(V1) - @@unique([jobId, environmentId, name]) -} + status TaskRunStatus @default(PENDING) + statusReason String? -model JobIntegration { - id String @id @default(cuid()) - key String + idempotencyKey String? + idempotencyKeyExpiresAt DateTime? + taskIdentifier String - version JobVersion @relation(fields: [versionId], references: [id], onDelete: Cascade, onUpdate: Cascade) - versionId String + isTest Boolean @default(false) - job Job @relation(fields: [jobId], references: [id], onDelete: Cascade, onUpdate: Cascade) - jobId String - - integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - integrationId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@unique([versionId, key]) -} - -model RunConnection { - id String @id @default(cuid()) - key String - - authSource IntegrationAuthSource @default(HOSTED) - - run JobRun @relation(fields: [runId], references: [id], onDelete: Cascade, onUpdate: Cascade) - runId String - - connection IntegrationConnection? @relation(fields: [connectionId], references: [id], onDelete: Cascade, onUpdate: Cascade) - connectionId String? - - integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - integrationId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - tasks Task[] - - @@unique([runId, key]) -} - -model DynamicTrigger { - id String @id @default(cuid()) - type DynamicTriggerType @default(EVENT) - slug String - - endpoint Endpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - endpointId String - - jobs Job[] - sources TriggerSource[] - scheduleSources ScheduleSource[] - registrations DynamicTriggerRegistration[] - - sourceRegistrationJob JobVersion? @relation(fields: [sourceRegistrationJobId], references: [id], onDelete: Cascade, onUpdate: Cascade) - sourceRegistrationJobId String? - - @@unique([endpointId, slug, type]) -} - -enum DynamicTriggerType { - EVENT - SCHEDULE -} - -model EventDispatcher { - id String @id @default(cuid()) - event String[] - source String - payloadFilter Json? - contextFilter Json? - manual Boolean @default(false) - - dispatchableId String - dispatchable Json - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - enabled Boolean @default(true) - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - registrations DynamicTriggerRegistration[] - scheduleSources ScheduleSource[] - - externalAccount ExternalAccount? @relation(fields: [externalAccountId], references: [id], onDelete: Cascade, onUpdate: Cascade) - externalAccountId String? - - @@unique([dispatchableId, environmentId]) -} - -enum JobStartPosition { - INITIAL - LATEST -} - -model EventRecord { - id String @id @default(cuid()) - eventId String - name String - timestamp DateTime @default(now()) - payload Json - payloadType PayloadType @default(JSON) - context Json? - sourceContext Json? - - source String @default("trigger.dev") - - organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - organizationId String - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) - projectId String - - externalAccount ExternalAccount? @relation(fields: [externalAccountId], references: [id], onDelete: Cascade, onUpdate: Cascade) - externalAccountId String? - - httpEndpoint TriggerHttpEndpoint? @relation(fields: [httpEndpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - httpEndpointId String? - - httpEndpointEnvironment TriggerHttpEndpointEnvironment? @relation(fields: [httpEndpointEnvironmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - httpEndpointEnvironmentId String? - - deliverAt DateTime @default(now()) - deliveredAt DateTime? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - cancelledAt DateTime? - - isTest Boolean @default(false) - internal Boolean @default(false) - runs JobRun[] - - @@unique([eventId, environmentId]) -} - -enum PayloadType { - JSON - REQUEST -} - -model JobRun { - id String @id @default(cuid()) - number Int? - internal Boolean @default(false) - - job Job @relation(fields: [jobId], references: [id], onDelete: Cascade, onUpdate: Cascade) - jobId String - - version JobVersion @relation(fields: [versionId], references: [id], onDelete: Cascade, onUpdate: Cascade) - versionId String - - event EventRecord @relation(fields: [eventId], references: [id], onDelete: Cascade, onUpdate: Cascade) - eventId String - - organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - organizationId String - - endpoint Endpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - endpointId String - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) - projectId String - - queue JobQueue? @relation(fields: [queueId], references: [id]) - queueId String? - - externalAccount ExternalAccount? @relation(fields: [externalAccountId], references: [id], onDelete: Cascade, onUpdate: Cascade) - externalAccountId String? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - queuedAt DateTime? - startedAt DateTime? - completedAt DateTime? - - properties Json? - - status JobRunStatus @default(PENDING) - output Json? - - timedOutAt DateTime? - timedOutReason String? - - executionCount Int @default(0) - executionFailureCount Int @default(0) - executionDuration Int @default(0) - - isTest Boolean @default(false) - preprocess Boolean @default(false) - - yieldedExecutions String[] - - forceYieldImmediately Boolean @default(false) - - tasks Task[] - runConnections RunConnection[] - missingConnections MissingConnection[] - executions JobRunExecution[] - statuses JobRunStatusRecord[] - autoYieldExecution JobRunAutoYieldExecution[] - subscriptions JobRunSubscription[] - - @@index([jobId, createdAt(sort: Desc)], map: "idx_jobrun_jobId_createdAt") - @@index([organizationId, createdAt], map: "idx_jobrun_organizationId_createdAt") - @@index([versionId], map: "idx_jobrun_versionId") - @@index([eventId], map: "JobRun_eventId_idx") -} - -enum JobRunStatus { - PENDING - QUEUED - WAITING_ON_CONNECTIONS - PREPROCESSING - STARTED - EXECUTING - WAITING_TO_CONTINUE - WAITING_TO_EXECUTE - SUCCESS - FAILURE - TIMED_OUT - ABORTED - CANCELED - UNRESOLVED_AUTH - INVALID_PAYLOAD -} - -model JobCounter { - jobId String @id - lastNumber Int @default(0) -} - -model JobRunAutoYieldExecution { - id String @id @default(cuid()) - - run JobRun @relation(fields: [runId], references: [id], onDelete: Cascade, onUpdate: Cascade) - runId String - - timeRemaining Int - timeElapsed Int - limit Int - location String - - createdAt DateTime @default(now()) -} - -model JobRunSubscription { - id String @id @default(cuid()) - - run JobRun @relation(fields: [runId], references: [id], onDelete: Cascade, onUpdate: Cascade) - runId String - - recipient String - recipientMethod JobRunSubscriptionRecipientMethod @default(WEBHOOK) - - event JobRunSubscriptionEvents - status JobRunSubscriptionStatus @default(ACTIVE) - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - deliveredAt DateTime? - - @@unique([runId, recipient, event]) -} - -enum JobRunSubscriptionRecipientMethod { - WEBHOOK - ENDPOINT -} - -enum JobRunSubscriptionStatus { - ACTIVE - INACTIVE -} - -enum JobRunSubscriptionEvents { - SUCCESS - FAILURE -} - -model JobRunExecution { - id String @id @default(cuid()) - - run JobRun @relation(fields: [runId], references: [id], onDelete: Cascade, onUpdate: Cascade) - runId String - - retryCount Int @default(0) - retryLimit Int @default(0) - retryDelayInMs Int @default(0) - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - startedAt DateTime? - completedAt DateTime? - - error String? - - reason JobRunExecutionReason @default(EXECUTE_JOB) - status JobRunExecutionStatus @default(PENDING) - - resumeTask Task? @relation(fields: [resumeTaskId], references: [id], onDelete: SetNull, onUpdate: Cascade) - resumeTaskId String? - - graphileJobId String? - - isRetry Boolean @default(false) -} - -enum JobRunExecutionReason { - PREPROCESS - EXECUTE_JOB -} - -enum JobRunExecutionStatus { - PENDING - STARTED - SUCCESS - FAILURE -} - -model Task { - id String @id - idempotencyKey String - displayKey String? - name String - icon String? - - status TaskStatus @default(PENDING) - delayUntil DateTime? - noop Boolean @default(false) - - description String? - properties Json? - outputProperties Json? - params Json? - output Json? - outputIsUndefined Boolean @default(false) - context Json? - error String? - redact Json? - style Json? - operation String? - callbackUrl String? - - startedAt DateTime? - completedAt DateTime? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - run JobRun @relation(fields: [runId], references: [id], onDelete: Cascade, onUpdate: Cascade) - runId String - - parent Task? @relation("TaskParent", fields: [parentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - parentId String? - - runConnection RunConnection? @relation(fields: [runConnectionId], references: [id], onDelete: Cascade, onUpdate: Cascade) - runConnectionId String? - - children Task[] @relation("TaskParent") - childExecutionMode TaskChildExecutionMode @default(SEQUENTIAL) - executions JobRunExecution[] - attempts TaskAttempt[] - - @@unique([runId, idempotencyKey]) - @@index([parentId], map: "idx_task_parentId") -} - -enum TaskStatus { - PENDING - WAITING - RUNNING - COMPLETED - ERRORED - CANCELED -} - -enum TaskChildExecutionMode { - SEQUENTIAL - PARALLEL -} - -model TaskAttempt { - id String @id @default(cuid()) - - number Int - - task Task @relation(fields: [taskId], references: [id], onDelete: Cascade, onUpdate: Cascade) - taskId String - - status TaskAttemptStatus @default(PENDING) - - error String? - - runAt DateTime? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@unique([taskId, number]) -} - -enum TaskAttemptStatus { - PENDING - STARTED - COMPLETED - ERRORED -} - -model JobRunStatusRecord { - id String @id @default(cuid()) - key String - - run JobRun @relation(fields: [runId], references: [id], onDelete: Cascade, onUpdate: Cascade) - runId String - - label String - state String? - data Json? - - history Json? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@unique([runId, key]) -} - -model SecretReference { - id String @id @default(cuid()) - key String @unique - provider SecretStoreProvider @default(DATABASE) - - connections IntegrationConnection[] - integrations Integration[] - triggerSources TriggerSource[] - httpEndpoints TriggerHttpEndpoint[] - environmentVariableValues EnvironmentVariableValue[] - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - OrganizationIntegration OrganizationIntegration[] -} - -enum SecretStoreProvider { - DATABASE - AWS_PARAM_STORE -} - -model SecretStore { - key String @unique - value Json - version String @default("1") - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@index([key(ops: raw("text_pattern_ops"))], type: BTree) -} - -model TriggerSource { - id String @id @default(cuid()) - - key String - params Json? - - channel TriggerChannel @default(HTTP) - channelData Json? - - version String @default("1") - - options TriggerSourceOption[] - - metadata Json? - - secretReference SecretReference @relation(fields: [secretReferenceId], references: [id], onDelete: Cascade, onUpdate: Cascade) - secretReferenceId String - - organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - organizationId String - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - endpoint Endpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - endpointId String - - project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) - projectId String - - integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - integrationId String - - dynamicTrigger DynamicTrigger? @relation(fields: [dynamicTriggerId], references: [id], onDelete: Cascade, onUpdate: Cascade) - dynamicTriggerId String? - - externalAccount ExternalAccount? @relation(fields: [externalAccountId], references: [id], onDelete: Cascade, onUpdate: Cascade) - externalAccountId String? - - sourceRegistrationJob JobVersion? @relation(fields: [sourceRegistrationJobId], references: [id], onDelete: Cascade, onUpdate: Cascade) - sourceRegistrationJobId String? - - dynamicSourceId String? - dynamicSourceMetadata Json? - - active Boolean @default(false) - interactive Boolean @default(false) - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - httpDeliveries HttpSourceRequestDelivery[] - registrations DynamicTriggerRegistration[] - - @@unique([key, environmentId]) -} - -enum TriggerChannel { - HTTP - SQS - SMTP -} - -model TriggerSourceOption { - id String @id @default(cuid()) - name String - value String - - source TriggerSource @relation(fields: [sourceId], references: [id], onDelete: Cascade, onUpdate: Cascade) - sourceId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - registered Boolean @default(false) - - @@unique([name, value, sourceId]) -} - -model Webhook { - id String @id @default(cuid()) - - active Boolean @default(false) - - key String - params Json? - - webhookEnvironments WebhookEnvironment[] - requestDeliveries WebhookRequestDelivery[] - - httpEndpoint TriggerHttpEndpoint @relation(fields: [httpEndpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - httpEndpointId String @unique - - project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) - projectId String - - integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - integrationId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@unique([key, projectId]) -} - -model WebhookEnvironment { - id String @id @default(cuid()) - - active Boolean @default(false) - - config Json? - desiredConfig Json? - - requestDeliveries WebhookRequestDelivery[] - - endpoint Endpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - endpointId String - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - webhook Webhook @relation(fields: [webhookId], references: [id], onDelete: Cascade, onUpdate: Cascade) - webhookId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@unique([environmentId, webhookId]) -} - -model WebhookRequestDelivery { - id String @id @default(cuid()) - number Int - - url String - method String - headers Json - - body Bytes? - - verified Boolean @default(false) - error String? - - webhook Webhook @relation(fields: [webhookId], references: [id], onDelete: Cascade, onUpdate: Cascade) - webhookId String - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - webhookEnvironment WebhookEnvironment @relation(fields: [webhookEnvironmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - webhookEnvironmentId String - - endpoint Endpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - endpointId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - deliveredAt DateTime? -} - -model WebhookDeliveryCounter { - webhookId String @id - lastNumber Int @default(0) -} - -model DynamicTriggerRegistration { - id String @id @default(cuid()) - - key String - - dynamicTrigger DynamicTrigger @relation(fields: [dynamicTriggerId], references: [id], onDelete: Cascade, onUpdate: Cascade) - dynamicTriggerId String - - eventDispatcher EventDispatcher @relation(fields: [eventDispatcherId], references: [id], onDelete: Cascade, onUpdate: Cascade) - eventDispatcherId String - - source TriggerSource @relation(fields: [sourceId], references: [id], onDelete: Cascade, onUpdate: Cascade) - sourceId String - - metadata Json? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@unique([key, dynamicTriggerId]) -} - -model HttpSourceRequestDelivery { - id String @id @default(cuid()) - url String - method String - headers Json - body Bytes? - - source TriggerSource @relation(fields: [sourceId], references: [id], onDelete: Cascade, onUpdate: Cascade) - sourceId String - - endpoint Endpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - endpointId String - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - deliveredAt DateTime? -} - -model ScheduleSource { - id String @id @default(cuid()) - - key String - schedule Json - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - dispatcher EventDispatcher @relation(fields: [dispatcherId], references: [id], onDelete: Cascade, onUpdate: Cascade) - dispatcherId String - - lastEventTimestamp DateTime? - nextEventTimestamp DateTime? - - workerJobId String? - - active Boolean @default(false) - - metadata Json? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - dynamicTrigger DynamicTrigger? @relation(fields: [dynamicTriggerId], references: [id], onDelete: Cascade, onUpdate: Cascade) - dynamicTriggerId String? - - externalAccount ExternalAccount? @relation(fields: [externalAccountId], references: [id], onDelete: Cascade, onUpdate: Cascade) - externalAccountId String? - deferredEvent DeferredScheduledEventService? - - @@unique([key, environmentId]) -} - -model TriggerHttpEndpoint { - id String @id @default(cuid()) - - key String - - title String? - icon String? - properties Json? - - webhook Webhook? - - secretReference SecretReference @relation(fields: [secretReferenceId], references: [id], onDelete: Cascade, onUpdate: Cascade) - secretReferenceId String - - project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) - projectId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - httpEndpointEnvironments TriggerHttpEndpointEnvironment[] - - eventRecords EventRecord[] - - @@unique([key, projectId]) -} - -model TriggerHttpEndpointEnvironment { - id String @id @default(cuid()) - - active Boolean @default(false) - - /// If this is set, requests will be tested against the filter and we'll call the user's server immediately - immediateResponseFilter Json? - - skipTriggeringRuns Boolean @default(false) - - source String - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - endpoint Endpoint @relation(fields: [endpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - endpointId String - - httpEndpoint TriggerHttpEndpoint @relation(fields: [httpEndpointId], references: [id], onDelete: Cascade, onUpdate: Cascade) - httpEndpointId String - - eventRecords EventRecord[] - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@unique([environmentId, httpEndpointId]) - @@unique([endpointId, httpEndpointId]) -} - -model KeyValueItem { - id String @id @default(cuid()) - - key String - value Bytes - - environment RuntimeEnvironment @relation(fields: [environmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - environmentId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@unique([environmentId, key]) - @@index([key], type: Hash) -} - -model MissingConnection { - id String @id @default(cuid()) - - resolved Boolean @default(false) - - runs JobRun[] - - integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - integrationId String - - connectionType ConnectionType @default(DEVELOPER) - - externalAccount ExternalAccount? @relation(fields: [externalAccountId], references: [id], onDelete: Cascade, onUpdate: Cascade) - externalAccountId String? - - accountIdentifier String? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@unique([integrationId, connectionType, externalAccountId]) - @@unique([integrationId, connectionType, accountIdentifier]) -} - -model ApiIntegrationVote { - id String @id @default(cuid()) - - apiIdentifier String - - user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade) - userId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - @@unique([apiIdentifier, userId]) -} - -model DataMigration { - id String @id @default(cuid()) - name String @unique - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - completedAt DateTime? -} - -model DeferredScheduledEventService { - id String @id @default(cuid()) - - scheduleSource ScheduleSource @relation(fields: [scheduleSourceId], references: [id], onDelete: Cascade, onUpdate: Cascade) - scheduleSourceId String @unique - - runAt DateTime - lastTimestamp DateTime? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} - -// ==================================================== -// v3 Models -// ==================================================== -model BackgroundWorker { - id String @id @default(cuid()) - - friendlyId String @unique - - engine RunEngineVersion @default(V1) - - contentHash String - sdkVersion String @default("unknown") - cliVersion String @default("unknown") - - project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) - projectId String - - runtimeEnvironment RuntimeEnvironment @relation(fields: [runtimeEnvironmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - runtimeEnvironmentId String - - version String - metadata Json - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - tasks BackgroundWorkerTask[] - attempts TaskRunAttempt[] - lockedRuns TaskRun[] - files BackgroundWorkerFile[] - queues TaskQueue[] - - deployment WorkerDeployment? - - workerGroup WorkerInstanceGroup? @relation(fields: [workerGroupId], references: [id], onDelete: SetNull, onUpdate: Cascade) - workerGroupId String? - - supportsLazyAttempts Boolean @default(false) - - @@unique([projectId, runtimeEnvironmentId, version]) - @@index([runtimeEnvironmentId]) - // Get the latest worker for a given environment - @@index([runtimeEnvironmentId, createdAt(sort: Desc)]) -} - -model BackgroundWorkerFile { - id String @id @default(cuid()) - - friendlyId String @unique - - filePath String - contentHash String - contents Bytes - - project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) - projectId String - - backgroundWorkers BackgroundWorker[] - - tasks BackgroundWorkerTask[] - - createdAt DateTime @default(now()) - - @@unique([projectId, contentHash]) -} - -model BackgroundWorkerTask { - id String @id @default(cuid()) - slug String - - description String? - - friendlyId String @unique - - filePath String - exportName String? - - worker BackgroundWorker @relation(fields: [workerId], references: [id], onDelete: Cascade, onUpdate: Cascade) - workerId String - - project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) - projectId String - - file BackgroundWorkerFile? @relation(fields: [fileId], references: [id], onDelete: Cascade, onUpdate: Cascade) - fileId String? - - runtimeEnvironment RuntimeEnvironment @relation(fields: [runtimeEnvironmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - runtimeEnvironmentId String - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - attempts TaskRunAttempt[] - runs TaskRun[] - - queueConfig Json? - retryConfig Json? - machineConfig Json? - - queueId String? - queue TaskQueue? @relation(fields: [queueId], references: [id], onDelete: SetNull, onUpdate: Cascade) - - maxDurationInSeconds Int? - - triggerSource TaskTriggerSource @default(STANDARD) - - @@unique([workerId, slug]) - // Quick lookup of task identifiers - @@index([projectId, slug]) - @@index([runtimeEnvironmentId, projectId]) -} - -enum TaskTriggerSource { - STANDARD - SCHEDULED -} - -model TaskRun { - id String @id @default(cuid()) - - number Int @default(0) - friendlyId String @unique - - engine RunEngineVersion @default(V1) - - status TaskRunStatus @default(PENDING) - statusReason String? - - idempotencyKey String? - idempotencyKeyExpiresAt DateTime? - taskIdentifier String - - isTest Boolean @default(false) - - payload String - payloadType String @default("application/json") - context Json? - traceContext Json? + payload String + payloadType String @default("application/json") + context Json? + traceContext Json? traceId String spanId String @@ -1764,7 +528,8 @@ model TaskRun { lockedQueueId String? /// The main queue that this run is part of - workerQueue String @default("main") @map("masterQueue") + workerQueue String @default("main") @map("masterQueue") + /// @deprecated secondaryMasterQueue String?