Skip to content

Add unique indexes for the oneTimeUseToken columns #1517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- A unique constraint covering the columns `[oneTimeUseToken]` on the table `TaskRun` will be added. If there are existing duplicate values, this will fail.

*/
-- CreateIndex
CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "TaskRun_oneTimeUseToken_key" ON "TaskRun"("oneTimeUseToken");
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- A unique constraint covering the columns `[oneTimeUseToken]` on the table `BatchTaskRun` will be added. If there are existing duplicate values, this will fail.

*/
-- CreateIndex
CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "BatchTaskRun_oneTimeUseToken_key" ON "BatchTaskRun"("oneTimeUseToken");
8 changes: 2 additions & 6 deletions internal-packages/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,6 @@ model TaskRun {
maxAttempts Int?

/// optional token that can be used to authenticate the task run
/// TODO: add a unique constraint on the token
oneTimeUseToken String?

batchItems BatchTaskRunItem[]
Expand Down Expand Up @@ -1791,8 +1790,7 @@ model TaskRun {

maxDurationInSeconds Int?

// TODO: uncomment this
// @@unique([oneTimeUseToken])
@@unique([oneTimeUseToken])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure existing data complies with the new unique constraint on oneTimeUseToken in TaskRun.

Adding a unique constraint to the oneTimeUseToken field enforces data integrity and uniqueness. However, if there are existing duplicate values in this column, the migration will fail. Please verify that the existing data does not contain duplicates before applying this change.

@@unique([runtimeEnvironmentId, taskIdentifier, idempotencyKey])
// Finding child runs
@@index([parentTaskRunId])
Expand Down Expand Up @@ -2168,7 +2166,6 @@ model BatchTaskRun {
batchVersion String @default("v1")

/// optional token that can be used to authenticate the task run
/// TODO: add a unique constraint on the token
oneTimeUseToken String?

///all the below properties are engine v1 only
Expand All @@ -2180,8 +2177,7 @@ model BatchTaskRun {
dependentTaskAttemptId String?
runDependencies TaskRunDependency[] @relation("dependentBatchRun")

// TODO: uncomment this
// @@unique([oneTimeUseToken])
@@unique([oneTimeUseToken])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure existing data complies with the new unique constraint on oneTimeUseToken in BatchTaskRun.

Similar to the TaskRun model, adding a unique constraint to the oneTimeUseToken field in the BatchTaskRun model requires that all existing values are unique. Ensure there are no duplicates to prevent migration failures.

///this is used for all engine versions
@@unique([runtimeEnvironmentId, idempotencyKey])
}
Expand Down
18 changes: 1 addition & 17 deletions references/nextjs-realtime/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,7 @@ import { ImageUploadDropzone } from "@/components/ImageUploadButton";
import { auth } from "@trigger.dev/sdk/v3";

export default async function Home() {
const publicAccessToken = await auth.createPublicToken({
scopes: {
write: {
tasks: ["openai-streaming"],
},
},
});

const readAll = await auth.createPublicToken({
scopes: {
read: {
runs: true,
},
},
});

console.log({ publicAccessToken, readAll });
const publicAccessToken = await auth.createTriggerPublicToken("openai-streaming");

return (
<main className="grid grid-rows-[1fr_auto] min-h-screen items-center justify-center w-full bg-gray-900">
Expand Down