Skip to content

Commit c1b3d44

Browse files
committed
restructure the migrations to create the index concurrently
1 parent fc18a71 commit c1b3d44

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

packages/database/prisma/migrations/20240918150510_add_root_task_run_and_descendants/migration.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/database/prisma/migrations/20240919203806_add_depth_to_task_run/migration.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
-- AlterTable
22
ALTER TABLE "TaskRun" ADD COLUMN "batchId" TEXT,
3+
ADD COLUMN "depth" INTEGER NOT NULL DEFAULT 0,
34
ADD COLUMN "parentTaskRunAttemptId" TEXT,
45
ADD COLUMN "parentTaskRunId" TEXT,
5-
ADD COLUMN "resumeParentOnCompletion" BOOLEAN NOT NULL DEFAULT false;
6+
ADD COLUMN "resumeParentOnCompletion" BOOLEAN NOT NULL DEFAULT false,
7+
ADD COLUMN "rootTaskRunId" TEXT;
68

7-
-- CreateIndex
8-
CREATE INDEX "TaskRun_parentTaskRunId_idx" ON "TaskRun"("parentTaskRunId");
9+
-- AddForeignKey
10+
ALTER TABLE "TaskRun" ADD CONSTRAINT "TaskRun_rootTaskRunId_fkey" FOREIGN KEY ("rootTaskRunId") REFERENCES "TaskRun"("id") ON DELETE SET NULL ON UPDATE NO ACTION;
911

1012
-- AddForeignKey
11-
ALTER TABLE "TaskRun" ADD CONSTRAINT "TaskRun_parentTaskRunId_fkey" FOREIGN KEY ("parentTaskRunId") REFERENCES "TaskRun"("id") ON DELETE SET NULL ON UPDATE CASCADE;
13+
ALTER TABLE "TaskRun" ADD CONSTRAINT "TaskRun_parentTaskRunId_fkey" FOREIGN KEY ("parentTaskRunId") REFERENCES "TaskRun"("id") ON DELETE SET NULL ON UPDATE NO ACTION;
1214

1315
-- AddForeignKey
14-
ALTER TABLE "TaskRun" ADD CONSTRAINT "TaskRun_parentTaskRunAttemptId_fkey" FOREIGN KEY ("parentTaskRunAttemptId") REFERENCES "TaskRunAttempt"("id") ON DELETE SET NULL ON UPDATE CASCADE;
16+
ALTER TABLE "TaskRun" ADD CONSTRAINT "TaskRun_parentTaskRunAttemptId_fkey" FOREIGN KEY ("parentTaskRunAttemptId") REFERENCES "TaskRunAttempt"("id") ON DELETE SET NULL ON UPDATE NO ACTION;
1517

1618
-- AddForeignKey
17-
ALTER TABLE "TaskRun" ADD CONSTRAINT "TaskRun_batchId_fkey" FOREIGN KEY ("batchId") REFERENCES "BatchTaskRun"("id") ON DELETE SET NULL ON UPDATE CASCADE;
19+
ALTER TABLE "TaskRun" ADD CONSTRAINT "TaskRun_batchId_fkey" FOREIGN KEY ("batchId") REFERENCES "BatchTaskRun"("id") ON DELETE SET NULL ON UPDATE NO ACTION;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- CreateIndex
2+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "TaskRun_parentTaskRunId_idx" ON "TaskRun"("parentTaskRunId");

packages/database/prisma/schema.prisma

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,25 +1721,25 @@ model TaskRun {
17211721
logsDeletedAt DateTime?
17221722
17231723
/// This represents the original task that that was triggered outside of a Trigger.dev task
1724-
rootTaskRun TaskRun? @relation("TaskRootRun", fields: [rootTaskRunId], references: [id], onDelete: SetNull)
1724+
rootTaskRun TaskRun? @relation("TaskRootRun", fields: [rootTaskRunId], references: [id], onDelete: SetNull, onUpdate: NoAction)
17251725
rootTaskRunId String?
17261726
17271727
/// The root run will have a list of all the descendant runs, children, grand children, etc.
17281728
descendantRuns TaskRun[] @relation("TaskRootRun")
17291729
17301730
/// The immediate parent run of this task run
1731-
parentTaskRun TaskRun? @relation("TaskParentRun", fields: [parentTaskRunId], references: [id], onDelete: SetNull)
1731+
parentTaskRun TaskRun? @relation("TaskParentRun", fields: [parentTaskRunId], references: [id], onDelete: SetNull, onUpdate: NoAction)
17321732
parentTaskRunId String?
17331733
17341734
/// The immediate child runs of this task run
17351735
childRuns TaskRun[] @relation("TaskParentRun")
17361736
17371737
/// The immediate parent attempt of this task run
1738-
parentTaskRunAttempt TaskRunAttempt? @relation("TaskParentRunAttempt", fields: [parentTaskRunAttemptId], references: [id], onDelete: SetNull)
1738+
parentTaskRunAttempt TaskRunAttempt? @relation("TaskParentRunAttempt", fields: [parentTaskRunAttemptId], references: [id], onDelete: SetNull, onUpdate: NoAction)
17391739
parentTaskRunAttemptId String?
17401740
17411741
/// The batch run that this task run is a part of
1742-
batch BatchTaskRun? @relation(fields: [batchId], references: [id], onDelete: SetNull)
1742+
batch BatchTaskRun? @relation(fields: [batchId], references: [id], onDelete: SetNull, onUpdate: NoAction)
17431743
batchId String?
17441744
17451745
/// whether or not the task run was created because of a triggerAndWait for batchTriggerAndWait
@@ -1749,6 +1749,8 @@ model TaskRun {
17491749
depth Int @default(0)
17501750
17511751
@@unique([runtimeEnvironmentId, taskIdentifier, idempotencyKey])
1752+
// Finding child runs
1753+
@@index([parentTaskRunId])
17521754
// Task activity graph
17531755
@@index([projectId, createdAt, taskIdentifier])
17541756
//Runs list
@@ -1762,8 +1764,6 @@ model TaskRun {
17621764
@@index([spanId])
17631765
// Finding completed runs
17641766
@@index([completedAt])
1765-
// Finding child runs
1766-
@@index([parentTaskRunId])
17671767
}
17681768

17691769
enum TaskRunStatus {

0 commit comments

Comments
 (0)