-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathschema.prisma
More file actions
2581 lines (1906 loc) · 73.9 KB
/
schema.prisma
File metadata and controls
2581 lines (1906 loc) · 73.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
generator client {
provider = "prisma-client-js"
output = "../generated/prisma"
binaryTargets = ["native", "debian-openssl-1.1.x"]
previewFeatures = ["metrics"]
}
model User {
id String @id @default(cuid())
email String @unique
authenticationMethod AuthenticationMethod
authenticationProfile Json?
authenticationExtraParams Json?
authIdentifier String? @unique
displayName String?
name String?
avatarUrl String?
admin Boolean @default(false)
/// Preferences for the dashboard
dashboardPreferences Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
/// @deprecated
isOnCloudWaitlist Boolean @default(false)
/// @deprecated
featureCloud Boolean @default(false)
/// @deprecated
isOnHostedRepoWaitlist Boolean @default(false)
marketingEmails Boolean @default(true)
confirmedBasicDetails Boolean @default(false)
referralSource String?
onboardingData Json?
orgMemberships OrgMember[]
sentInvites OrgMemberInvite[]
mfaEnabledAt DateTime?
mfaSecretReference SecretReference? @relation(fields: [mfaSecretReferenceId], references: [id])
mfaSecretReferenceId String?
/// Hash of the last used code to prevent replay attacks
mfaLastUsedCode String?
invitationCode InvitationCode? @relation(fields: [invitationCodeId], references: [id])
invitationCodeId String?
personalAccessTokens PersonalAccessToken[]
deployments WorkerDeployment[]
backupCodes MfaBackupCode[]
bulkActions BulkActionGroup[]
impersonationsPerformed ImpersonationAuditLog[] @relation("ImpersonationAdmin")
impersonationsReceived ImpersonationAuditLog[] @relation("ImpersonationTarget")
customerQueries CustomerQuery[]
metricsDashboards MetricsDashboard[]
}
model MfaBackupCode {
id String @id @default(cuid())
/// Hash of the actual code
code String
user User @relation(fields: [userId], references: [id])
userId String
usedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([userId, code])
}
// @deprecated This model is no longer used as the Cloud is out of private beta
// Leaving it here for now for historical reasons
model InvitationCode {
id String @id @default(cuid())
code String @unique
users User[]
createdAt DateTime @default(now())
}
enum AuthenticationMethod {
GITHUB
MAGIC_LINK
GOOGLE
}
/// Used to generate PersonalAccessTokens, they're one-time use
model AuthorizationCode {
id String @id @default(cuid())
code String @unique
personalAccessToken PersonalAccessToken? @relation(fields: [personalAccessTokenId], references: [id], onDelete: Cascade, onUpdate: Cascade)
personalAccessTokenId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
// Used by User's to perform API actions
model PersonalAccessToken {
id String @id @default(cuid())
/// If generated by the CLI this will be "cli", otherwise user-provided
name String
/// This is the token encrypted using the ENCRYPTION_KEY
encryptedToken Json
/// This is shown in the UI, with ********
obfuscatedToken String
/// This is used to find the token in the database
hashedToken String @unique
user User @relation(fields: [userId], references: [id])
userId String
revokedAt DateTime?
lastAccessedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
authorizationCodes AuthorizationCode[]
}
enum OrganizationAccessTokenType {
USER
SYSTEM
}
model OrganizationAccessToken {
id String @id @default(cuid())
/// User-provided name for the token
name String
/// Used to differentiate between user-generated and system-generated tokens
type OrganizationAccessTokenType @default(USER)
/// This is used to find the token in the database
hashedToken String @unique
organization Organization @relation(fields: [organizationId], references: [id])
organizationId String
/// Optional expiration date for the token
expiresAt DateTime?
revokedAt DateTime?
lastAccessedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([organizationId, type, createdAt(sort: Desc)])
}
model Organization {
id String @id @default(cuid())
slug String @unique
title String
maximumExecutionTimePerRunInMs Int @default(900000) // 15 minutes
maximumConcurrencyLimit Int @default(10)
/// This is deprecated and will be removed in the future
maximumSchedulesLimit Int @default(5)
maximumDevQueueSize Int?
maximumDeployedQueueSize Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
companySize String?
onboardingData Json?
avatar Json?
runsEnabled Boolean @default(true)
v3Enabled Boolean @default(false)
/// @deprecated
v2Enabled Boolean @default(false)
/// @deprecated
v2MarqsEnabled Boolean @default(false)
/// @deprecated
hasRequestedV3 Boolean @default(false)
environments RuntimeEnvironment[]
apiRateLimiterConfig Json?
realtimeRateLimiterConfig Json?
batchRateLimitConfig Json?
batchQueueConcurrencyConfig Json?
featureFlags Json?
maximumProjectCount Int @default(10)
projects Project[]
members OrgMember[]
invites OrgMemberInvite[]
organizationIntegrations OrganizationIntegration[]
organizationAccessTokens OrganizationAccessToken[]
workerGroups WorkerInstanceGroup[]
workerInstances WorkerInstance[]
githubAppInstallations GithubAppInstallation[]
customerQueries CustomerQuery[]
metricsDashboards MetricsDashboard[]
}
model OrgMember {
id String @id @default(cuid())
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade)
organizationId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
userId String
role OrgMemberRole @default(MEMBER)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
environments RuntimeEnvironment[]
@@unique([organizationId, userId])
}
enum OrgMemberRole {
ADMIN
MEMBER
}
model OrgMemberInvite {
id String @id @default(cuid())
token String @unique @default(cuid())
email String
role OrgMemberRole @default(MEMBER)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade)
organizationId String
inviter User @relation(fields: [inviterId], references: [id], onDelete: Cascade, onUpdate: Cascade)
inviterId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([organizationId, email])
}
model RuntimeEnvironment {
id String @id @default(cuid())
slug String
apiKey String @unique
/// @deprecated was for v2
pkApiKey String @unique
type RuntimeEnvironmentType @default(DEVELOPMENT)
// Preview branches
/// If true, this environment has branches and is treated differently in the dashboard/API
isBranchableEnvironment Boolean @default(false)
branchName String?
parentEnvironment RuntimeEnvironment? @relation("parentEnvironment", fields: [parentEnvironmentId], references: [id], onDelete: Cascade, onUpdate: Cascade)
parentEnvironmentId String?
childEnvironments RuntimeEnvironment[] @relation("parentEnvironment")
// This is GitMeta type
git Json?
/// When set API calls will fail
archivedAt DateTime?
///A memorable code for the environment
shortcode String
maximumConcurrencyLimit Int @default(5)
concurrencyLimitBurstFactor Decimal @default("2.00") @db.Decimal(4, 2)
paused Boolean @default(false)
autoEnableInternalSources Boolean @default(true)
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
//when the org member is deleted, it will keep the environment but set it to null
orgMember OrgMember? @relation(fields: [orgMemberId], references: [id], onDelete: SetNull, onUpdate: Cascade)
orgMemberId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
/// Allows us to customize the built-in environment variables for a specific environment, like TRIGGER_OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT
builtInEnvironmentVariableOverrides Json?
tunnelId String?
backgroundWorkers BackgroundWorker[]
backgroundWorkerTasks BackgroundWorkerTask[]
taskRuns TaskRun[]
taskQueues TaskQueue[]
batchTaskRuns BatchTaskRun[]
environmentVariableValues EnvironmentVariableValue[]
checkpoints Checkpoint[]
workerDeployments WorkerDeployment[]
workerDeploymentPromotions WorkerDeploymentPromotion[]
taskRunAttempts TaskRunAttempt[]
CheckpointRestoreEvent CheckpointRestoreEvent[]
taskScheduleInstances TaskScheduleInstance[]
alerts ProjectAlert[]
sessions RuntimeEnvironmentSession[]
currentSession RuntimeEnvironmentSession? @relation("currentSession", fields: [currentSessionId], references: [id], onDelete: SetNull, onUpdate: Cascade)
currentSessionId String?
taskRunNumberCounter TaskRunNumberCounter[]
taskRunCheckpoints TaskRunCheckpoint[]
waitpoints Waitpoint[]
workerInstances WorkerInstance[]
waitpointTags WaitpointTag[]
BulkActionGroup BulkActionGroup[]
customerQueries CustomerQuery[]
@@unique([projectId, slug, orgMemberId])
@@unique([projectId, shortcode])
@@index([parentEnvironmentId])
@@index([projectId])
@@index([organizationId])
}
enum RuntimeEnvironmentType {
PRODUCTION
STAGING
DEVELOPMENT
PREVIEW
}
model Project {
id String @id @default(cuid())
slug String @unique
name String
externalRef String @unique
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade)
organizationId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
version ProjectVersion @default(V2)
engine RunEngineVersion @default(V1)
builderProjectId String?
workerGroups WorkerInstanceGroup[]
workers WorkerInstance[]
defaultWorkerGroup WorkerInstanceGroup? @relation("ProjectDefaultWorkerGroup", fields: [defaultWorkerGroupId], references: [id])
defaultWorkerGroupId String?
/// The master queues they are allowed to use (impacts what they can set as default and trigger runs with)
allowedWorkerQueues String[] @default([]) @map("allowedMasterQueues")
environments RuntimeEnvironment[]
backgroundWorkers BackgroundWorker[]
backgroundWorkerTasks BackgroundWorkerTask[]
taskRuns TaskRun[]
runTags TaskRunTag[]
taskQueues TaskQueue[]
environmentVariables EnvironmentVariable[]
checkpoints Checkpoint[]
WorkerDeployment WorkerDeployment[]
CheckpointRestoreEvent CheckpointRestoreEvent[]
taskSchedules TaskSchedule[]
alertChannels ProjectAlertChannel[]
alerts ProjectAlert[]
alertStorages ProjectAlertStorage[]
bulkActionGroups BulkActionGroup[]
BackgroundWorkerFile BackgroundWorkerFile[]
waitpoints Waitpoint[]
taskRunWaitpoints TaskRunWaitpoint[]
taskRunCheckpoints TaskRunCheckpoint[]
waitpointTags WaitpointTag[]
connectedGithubRepository ConnectedGithubRepository?
organizationProjectIntegration OrganizationProjectIntegration[]
customerQueries CustomerQuery[]
buildSettings Json?
onboardingData Json?
taskScheduleInstances TaskScheduleInstance[]
metricsDashboards MetricsDashboard[]
}
enum ProjectVersion {
V2
V3
}
model SecretReference {
id String @id @default(cuid())
key String @unique
provider SecretStoreProvider @default(DATABASE)
environmentVariableValues EnvironmentVariableValue[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
OrganizationIntegration OrganizationIntegration[]
User User[]
}
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 DataMigration {
id String @id @default(cuid())
name String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
completedAt DateTime?
}
// ====================================================
// 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
runtime String?
runtimeVersion String?
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?
ttl String?
triggerSource TaskTriggerSource @default(STANDARD)
payloadSchema Json?
@@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?
/// Stores the user-provided key and scope: { key: string, scope: "run" | "attempt" | "global" }
idempotencyKeyOptions Json?
/// Debounce options: { key: string, delay: string, createdAt: Date }
debounce Json?
taskIdentifier String
isTest Boolean @default(false)
payload String
payloadType String @default("application/json")
context Json?
traceContext Json?
traceId String
spanId String
runtimeEnvironment RuntimeEnvironment @relation(fields: [runtimeEnvironmentId], references: [id], onDelete: Cascade, onUpdate: Cascade)
runtimeEnvironmentId String
environmentType RuntimeEnvironmentType?
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade)
projectId String
organizationId String?
// The specific queue this run is in
queue String
// The queueId is set when the run is locked to a specific queue
lockedQueueId String?
/// The main queue that this run is part of
workerQueue String @default("main") @map("masterQueue")
/// @deprecated
secondaryMasterQueue String?
/// From engine v2+ this will be defined after a run has been dequeued (starting at 1)
attemptNumber Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
attempts TaskRunAttempt[] @relation("attempts")
tags TaskRunTag[]
/// Denormized column that holds the raw tags
runTags String[]
/// Denormalized version of the background worker task
taskVersion String?
sdkVersion String?
cliVersion String?
checkpoints Checkpoint[]
/// startedAt marks the point at which a run is dequeued from MarQS
startedAt DateTime?
/// executedAt is set when the first attempt is about to execute
executedAt DateTime?
completedAt DateTime?
machinePreset String?
usageDurationMs Int @default(0)
costInCents Float @default(0)
baseCostInCents Float @default(0)
lockedAt DateTime?
lockedBy BackgroundWorkerTask? @relation(fields: [lockedById], references: [id])
lockedById String?
lockedToVersion BackgroundWorker? @relation(fields: [lockedToVersionId], references: [id])
lockedToVersionId String?
/// The "priority" of the run. This is just a negative offset in ms for the queue timestamp
/// E.g. a value of 60_000 would put the run into the queue 60s ago.
priorityMs Int @default(0)
concurrencyKey String?
delayUntil DateTime?
queuedAt DateTime?
ttl String?
expiredAt DateTime?
maxAttempts Int?
lockedRetryConfig Json?
/// optional token that can be used to authenticate the task run
oneTimeUseToken String?
///When this run is finished, the waitpoint will be marked as completed
associatedWaitpoint Waitpoint? @relation("CompletingRun")
///If there are any blocked waitpoints, the run won't be executed
blockedByWaitpoints TaskRunWaitpoint[]
/// All waitpoints that blocked this run at some point, used for display purposes
connectedWaitpoints Waitpoint[] @relation("WaitpointRunConnections")
/// Where the logs are stored
taskEventStore String @default("taskEvent")
queueTimestamp DateTime?
batchItems BatchTaskRunItem[]
dependency TaskRunDependency?
CheckpointRestoreEvent CheckpointRestoreEvent[]
executionSnapshots TaskRunExecutionSnapshot[]
alerts ProjectAlert[]
scheduleInstanceId String?
scheduleId String?
sourceBulkActionItems BulkActionItem[] @relation("SourceActionItemRun")
destinationBulkActionItems BulkActionItem[] @relation("DestinationActionItemRun")
bulkActionGroupIds String[] @default([])
logsDeletedAt DateTime?
replayedFromTaskRunFriendlyId String?
/// This represents the original task that that was triggered outside of a Trigger.dev task
rootTaskRun TaskRun? @relation("TaskRootRun", fields: [rootTaskRunId], references: [id], onDelete: SetNull, onUpdate: NoAction)
rootTaskRunId String?
/// The root run will have a list of all the descendant runs, children, grand children, etc.
descendantRuns TaskRun[] @relation("TaskRootRun")
/// The immediate parent run of this task run
parentTaskRun TaskRun? @relation("TaskParentRun", fields: [parentTaskRunId], references: [id], onDelete: SetNull, onUpdate: NoAction)
parentTaskRunId String?
/// The immediate child runs of this task run
childRuns TaskRun[] @relation("TaskParentRun")
/// The immediate parent attempt of this task run
parentTaskRunAttempt TaskRunAttempt? @relation("TaskParentRunAttempt", fields: [parentTaskRunAttemptId], references: [id], onDelete: SetNull, onUpdate: NoAction)
parentTaskRunAttemptId String?
/// The batch run that this task run is a part of
batch BatchTaskRun? @relation(fields: [batchId], references: [id], onDelete: SetNull, onUpdate: NoAction)
batchId String?
/// whether or not the task run was created because of a triggerAndWait for batchTriggerAndWait
resumeParentOnCompletion Boolean @default(false)
/// The depth of this task run in the task run hierarchy
depth Int @default(0)
/// The span ID of the "trigger" span in the parent task run
parentSpanId String?
/// Holds the state of the run chain for deadlock detection
runChainState Json?
/// seed run metadata
seedMetadata String?
seedMetadataType String @default("application/json")
/// Run metadata
metadata String?
metadataType String @default("application/json")
metadataVersion Int @default(1)
/// Run output
output String?
outputType String @default("application/json")
/// Run error
error Json?
/// Organization's billing plan type (cached for fallback when billing API fails)
planType String?
maxDurationInSeconds Int?
/// The version of the realtime streams implementation used by the run
realtimeStreamsVersion String @default("v1")
/// Store the stream keys that are being used by the run
realtimeStreams String[] @default([])
@@unique([oneTimeUseToken])
@@unique([runtimeEnvironmentId, taskIdentifier, idempotencyKey])
// Finding child runs
@@index([parentTaskRunId])
// Finding ancestor runs
@@index([rootTaskRunId])
//Schedules
@@index([scheduleId])
// Run page inspector
@@index([spanId])
@@index([parentSpanId])
// Schedule list page
@@index([scheduleId, createdAt(sort: Desc)])
// Finding runs in a batch
@@index([runTags(ops: ArrayOps)], type: Gin)
@@index([runtimeEnvironmentId, batchId])
// This will include the createdAt index to help speed up the run list page
@@index([runtimeEnvironmentId, id(sort: Desc)])
@@index([runtimeEnvironmentId, createdAt(sort: Desc)])
@@index([createdAt], type: Brin)
@@index([status, runtimeEnvironmentId, createdAt, id(sort: Desc)])
}
model TaskRunTemplate {
id String @id @default(cuid())
taskSlug String
triggerSource TaskTriggerSource
label String
payload String?
payloadType String @default("application/json")
metadata String?
metadataType String @default("application/json")
queue String?
concurrencyKey String?
ttlSeconds Int?
maxAttempts Int?
maxDurationSeconds Int?
tags String[]
machinePreset String?
projectId String
organizationId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([projectId, taskSlug, triggerSource, createdAt(sort: Desc)])
}
enum TaskRunStatus {
///
/// NON-FINAL STATUSES
///
/// Task has been scheduled to run in the future
DELAYED
/// Task is waiting to be executed by a worker
PENDING
/// The run is pending a version update because it cannot execute without additional information (task, queue, etc.). Replaces WAITING_FOR_DEPLOY
PENDING_VERSION
/// Task hasn't been deployed yet but is waiting to be executed. Deprecated in favor of PENDING_VERSION
WAITING_FOR_DEPLOY
/// Task has been dequeued from the queue but is not yet executing
DEQUEUED
/// Task is currently being executed by a worker
EXECUTING
/// Task has been paused by the system, and will be resumed by the system
WAITING_TO_RESUME
/// Task has failed and is waiting to be retried
RETRYING_AFTER_FAILURE
/// Task has been paused by the user, and can be resumed by the user
PAUSED
///
/// FINAL STATUSES
///
/// Task has been canceled by the user
CANCELED
/// Task was interrupted during execution, mostly this happens in development environments
INTERRUPTED
/// Task has been completed successfully
COMPLETED_SUCCESSFULLY
/// Task has been completed with errors
COMPLETED_WITH_ERRORS
/// Task has failed to complete, due to an error in the system
SYSTEM_FAILURE
/// Task has crashed and won't be retried, most likely the worker ran out of resources, e.g. memory or storage
CRASHED
/// Task reached the ttl without being executed
EXPIRED
/// Task has been timed out when using maxDuration
TIMED_OUT
}
enum RunEngineVersion {
/// The original version that uses marqs v1 and Graphile
V1
V2
}
/// Used by the RunEngine during TaskRun execution
/// It has the required information to transactionally progress a run through states,
/// and prevent side effects like heartbeats failing a run that has progressed.
/// It is optimised for performance and is designed to be cleared at some point,
/// so there are no cascading relationships to other models.
model TaskRunExecutionSnapshot {
id String @id @default(cuid())
/// This should always be 2+ (V1 didn't use the run engine or snapshots)
engine RunEngineVersion @default(V2)
/// The execution status
executionStatus TaskRunExecutionStatus
/// For debugging
description String
/// We store invalid snapshots as a record of the run state when we tried to move
isValid Boolean @default(true)
error String?
/// The previous snapshot ID
previousSnapshotId String?
/// Run
runId String
run TaskRun @relation(fields: [runId], references: [id])
runStatus TaskRunStatus
// Batch
batchId String?
/// This is the current run attempt number. Users can define how many attempts they want for a run.
attemptNumber Int?
/// Environment
environmentId String
environmentType RuntimeEnvironmentType
projectId String
organizationId String
/// Waitpoints that have been completed for this execution
completedWaitpoints Waitpoint[] @relation("completedWaitpoints")
/// An array of waitpoint IDs in the correct order, used for batches
completedWaitpointOrder String[]
/// Checkpoint
checkpointId String?
checkpoint TaskRunCheckpoint? @relation(fields: [checkpointId], references: [id])
/// Worker
workerId String?
runnerId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lastHeartbeatAt DateTime?
/// Metadata used by various systems in the run engine
metadata Json?
/// Used to get the latest valid snapshot quickly
@@index([runId, isValid, createdAt(sort: Desc)])
}
enum TaskRunExecutionStatus {
/// Run has been created
RUN_CREATED
/// Run is delayed, waiting to be enqueued
DELAYED
/// Run is in the RunQueue
QUEUED
/// Run is in the RunQueue, and is also executing. This happens when a run is continued cannot reacquire concurrency
QUEUED_EXECUTING
/// Run has been pulled from the queue, but isn't executing yet
PENDING_EXECUTING
/// Run is executing on a worker
EXECUTING
/// Run is executing on a worker but is waiting for waitpoints to complete
EXECUTING_WITH_WAITPOINTS
/// Run has been suspended and may be waiting for waitpoints to complete before resuming
SUSPENDED
/// Run has been scheduled for cancellation
PENDING_CANCEL
/// Run is finished (success of failure)
FINISHED
}
model TaskRunCheckpoint {
id String @id @default(cuid())
friendlyId String @unique
type TaskRunCheckpointType