diff --git a/apps/webapp/app/db.server.ts b/apps/webapp/app/db.server.ts index 90942662d3..445d7fbf49 100644 --- a/apps/webapp/app/db.server.ts +++ b/apps/webapp/app/db.server.ts @@ -13,6 +13,8 @@ import { logger } from "./services/logger.server"; import { isValidDatabaseUrl } from "./utils/db"; import { singleton } from "./utils/singleton"; import { $transaction as transac } from "@trigger.dev/database"; +import { startActiveSpan } from "./v3/tracer.server"; +import { Span } from "@opentelemetry/api"; export type { PrismaTransactionClient, @@ -21,25 +23,76 @@ export type { PrismaReplicaClient, }; +export async function $transaction( + prisma: PrismaClientOrTransaction, + name: string, + fn: (prisma: PrismaTransactionClient, span?: Span) => Promise, + options?: PrismaTransactionOptions +): Promise; export async function $transaction( prisma: PrismaClientOrTransaction, fn: (prisma: PrismaTransactionClient) => Promise, options?: PrismaTransactionOptions +): Promise; +export async function $transaction( + prisma: PrismaClientOrTransaction, + fnOrName: ((prisma: PrismaTransactionClient) => Promise) | string, + fnOrOptions?: ((prisma: PrismaTransactionClient) => Promise) | PrismaTransactionOptions, + options?: PrismaTransactionOptions ): Promise { - return transac( - prisma, - fn, - (error) => { - logger.error("prisma.$transaction error", { - code: error.code, - meta: error.meta, - stack: error.stack, - message: error.message, - name: error.name, - }); - }, - options - ); + if (typeof fnOrName === "string") { + return await startActiveSpan(fnOrName, async (span) => { + span.setAttribute("$transaction", true); + + if (options?.isolationLevel) { + span.setAttribute("isolation_level", options.isolationLevel); + } + + if (options?.timeout) { + span.setAttribute("timeout", options.timeout); + } + + if (options?.maxWait) { + span.setAttribute("max_wait", options.maxWait); + } + + if (options?.swallowPrismaErrors) { + span.setAttribute("swallow_prisma_errors", options.swallowPrismaErrors); + } + + const fn = fnOrOptions as (prisma: PrismaTransactionClient, span: Span) => Promise; + + return transac( + prisma, + (client) => fn(client, span), + (error) => { + logger.error("prisma.$transaction error", { + code: error.code, + meta: error.meta, + stack: error.stack, + message: error.message, + name: error.name, + }); + }, + options + ); + }); + } else { + return transac( + prisma, + fnOrName, + (error) => { + logger.error("prisma.$transaction error", { + code: error.code, + meta: error.meta, + stack: error.stack, + message: error.message, + name: error.name, + }); + }, + typeof fnOrOptions === "function" ? undefined : fnOrOptions + ); + } } export { Prisma }; diff --git a/apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts b/apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts index d26efa559e..0b610215ef 100644 --- a/apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts @@ -9,7 +9,7 @@ export class ApiBatchResultsPresenter extends BasePresenter { env: AuthenticatedEnvironment ): Promise { return this.traceWithEnv("call", env, async (span) => { - const batchRun = await this._prisma.batchTaskRun.findUnique({ + const batchRun = await this._prisma.batchTaskRun.findFirst({ where: { friendlyId, runtimeEnvironmentId: env.id, diff --git a/apps/webapp/app/presenters/v3/ApiRunResultPresenter.server.ts b/apps/webapp/app/presenters/v3/ApiRunResultPresenter.server.ts index 01615dd6ca..c11a04a158 100644 --- a/apps/webapp/app/presenters/v3/ApiRunResultPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/ApiRunResultPresenter.server.ts @@ -9,7 +9,7 @@ export class ApiRunResultPresenter extends BasePresenter { env: AuthenticatedEnvironment ): Promise { return this.traceWithEnv("call", env, async (span) => { - const taskRun = await this._prisma.taskRun.findUnique({ + const taskRun = await this._prisma.taskRun.findFirst({ where: { friendlyId, runtimeEnvironmentId: env.id, diff --git a/apps/webapp/app/presenters/v3/DeploymentPresenter.server.ts b/apps/webapp/app/presenters/v3/DeploymentPresenter.server.ts index 04b12394ef..eafaf96300 100644 --- a/apps/webapp/app/presenters/v3/DeploymentPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/DeploymentPresenter.server.ts @@ -53,12 +53,10 @@ export class DeploymentPresenter { }, }); - const deployment = await this.#prismaClient.workerDeployment.findUniqueOrThrow({ + const deployment = await this.#prismaClient.workerDeployment.findFirstOrThrow({ where: { - projectId_shortCode: { - projectId: project.id, - shortCode: deploymentShortCode, - }, + projectId: project.id, + shortCode: deploymentShortCode, }, select: { id: true, diff --git a/apps/webapp/app/presenters/v3/EnvironmentVariablesPresenter.server.ts b/apps/webapp/app/presenters/v3/EnvironmentVariablesPresenter.server.ts index 0f745d6958..1123a66b62 100644 --- a/apps/webapp/app/presenters/v3/EnvironmentVariablesPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/EnvironmentVariablesPresenter.server.ts @@ -15,7 +15,7 @@ export class EnvironmentVariablesPresenter { } public async call({ userId, projectSlug }: { userId: User["id"]; projectSlug: Project["slug"] }) { - const project = await this.#prismaClient.project.findUnique({ + const project = await this.#prismaClient.project.findFirst({ select: { id: true, }, diff --git a/apps/webapp/app/presenters/v3/NewAlertChannelPresenter.server.ts b/apps/webapp/app/presenters/v3/NewAlertChannelPresenter.server.ts index dffa7a9cb3..5bf83bf493 100644 --- a/apps/webapp/app/presenters/v3/NewAlertChannelPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/NewAlertChannelPresenter.server.ts @@ -8,7 +8,7 @@ import { WebClient } from "@slack/web-api"; export class NewAlertChannelPresenter extends BasePresenter { public async call(projectId: string) { - const project = await this._prisma.project.findUniqueOrThrow({ + const project = await this._prisma.project.findFirstOrThrow({ where: { id: projectId, }, diff --git a/apps/webapp/app/presenters/v3/RunListPresenter.server.ts b/apps/webapp/app/presenters/v3/RunListPresenter.server.ts index 2deecbaa78..208466544c 100644 --- a/apps/webapp/app/presenters/v3/RunListPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/RunListPresenter.server.ts @@ -131,7 +131,7 @@ export class RunListPresenter extends BasePresenter { //bulk id if (bulkId) { - const bulkAction = await this._replica.bulkActionGroup.findUnique({ + const bulkAction = await this._replica.bulkActionGroup.findFirst({ select: { items: { select: { diff --git a/apps/webapp/app/presenters/v3/RunStreamPresenter.server.ts b/apps/webapp/app/presenters/v3/RunStreamPresenter.server.ts index 5df64c9ae3..978470c9ad 100644 --- a/apps/webapp/app/presenters/v3/RunStreamPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/RunStreamPresenter.server.ts @@ -21,7 +21,7 @@ export class RunStreamPresenter { request: Request; runFriendlyId: TaskRun["friendlyId"]; }) { - const run = await this.#prismaClient.taskRun.findUnique({ + const run = await this.#prismaClient.taskRun.findFirst({ where: { friendlyId: runFriendlyId, }, diff --git a/apps/webapp/app/presenters/v3/SpanPresenter.server.ts b/apps/webapp/app/presenters/v3/SpanPresenter.server.ts index d8516ca6ac..e1bac33dd0 100644 --- a/apps/webapp/app/presenters/v3/SpanPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/SpanPresenter.server.ts @@ -29,7 +29,7 @@ export class SpanPresenter extends BasePresenter { spanId: string; runFriendlyId: string; }) { - const project = await this._replica.project.findUnique({ + const project = await this._replica.project.findFirst({ where: { slug: projectSlug, }, diff --git a/apps/webapp/app/presenters/v3/TasksStreamPresenter.server.ts b/apps/webapp/app/presenters/v3/TasksStreamPresenter.server.ts index c7318c3400..963ead1c6f 100644 --- a/apps/webapp/app/presenters/v3/TasksStreamPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/TasksStreamPresenter.server.ts @@ -33,7 +33,7 @@ export class TasksStreamPresenter { projectSlug: string; userId: string; }) { - const project = await this.#prismaClient.project.findUnique({ + const project = await this.#prismaClient.project.findFirst({ where: { slug: projectSlug, organization: { diff --git a/apps/webapp/app/routes/api.v1.deployments.$deploymentId.ts b/apps/webapp/app/routes/api.v1.deployments.$deploymentId.ts index a28ef75048..d9131aab4c 100644 --- a/apps/webapp/app/routes/api.v1.deployments.$deploymentId.ts +++ b/apps/webapp/app/routes/api.v1.deployments.$deploymentId.ts @@ -27,7 +27,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) { const { deploymentId } = parsedParams.data; - const deployment = await prisma.workerDeployment.findUnique({ + const deployment = await prisma.workerDeployment.findFirst({ where: { friendlyId: deploymentId, environmentId: authenticatedEnv.id, diff --git a/apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.ts b/apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.ts index 8b83ff6a0d..4ea3960729 100644 --- a/apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.ts +++ b/apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.ts @@ -26,7 +26,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) { const { projectRef } = parsedParams.data; - const project = await prisma.project.findUnique({ + const project = await prisma.project.findFirst({ where: { externalRef: projectRef, environments: { diff --git a/apps/webapp/app/routes/api.v1.projects.$projectRef.ts b/apps/webapp/app/routes/api.v1.projects.$projectRef.ts index 3c88fc12b2..cd82393de9 100644 --- a/apps/webapp/app/routes/api.v1.projects.$projectRef.ts +++ b/apps/webapp/app/routes/api.v1.projects.$projectRef.ts @@ -27,7 +27,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) { const { projectRef } = parsedParams.data; - const project = await prisma.project.findUnique({ + const project = await prisma.project.findFirst({ where: { externalRef: projectRef, organization: { diff --git a/apps/webapp/app/services/autoIncrementCounter.server.ts b/apps/webapp/app/services/autoIncrementCounter.server.ts index 64aa76410d..205e6ef9c1 100644 --- a/apps/webapp/app/services/autoIncrementCounter.server.ts +++ b/apps/webapp/app/services/autoIncrementCounter.server.ts @@ -1,11 +1,5 @@ import Redis, { RedisOptions } from "ioredis"; -import { - $transaction, - Prisma, - PrismaClientOrTransaction, - PrismaTransactionOptions, - prisma, -} from "~/db.server"; +import { Prisma, PrismaClientOrTransaction, PrismaTransactionOptions, prisma } from "~/db.server"; import { env } from "~/env.server"; import { singleton } from "~/utils/singleton"; diff --git a/apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts b/apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts index b10a84d0e4..05970a4578 100644 --- a/apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts +++ b/apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts @@ -57,7 +57,7 @@ export class EnvironmentVariablesRepository implements Repository { }[]; } ): Promise { - const project = await this.prismaClient.project.findUnique({ + const project = await this.prismaClient.project.findFirst({ where: { id: projectId, deletedAt: null, @@ -136,7 +136,7 @@ export class EnvironmentVariablesRepository implements Repository { try { for (const variable of values) { - const result = await $transaction(this.prismaClient, async (tx) => { + const result = await $transaction(this.prismaClient, "create env var", async (tx) => { const environmentVariable = await tx.environmentVariable.upsert({ where: { projectId_key: { @@ -227,7 +227,7 @@ export class EnvironmentVariablesRepository implements Repository { keepEmptyValues?: boolean; } ): Promise { - const project = await this.prismaClient.project.findUnique({ + const project = await this.prismaClient.project.findFirst({ where: { id: projectId, deletedAt: null, @@ -266,7 +266,7 @@ export class EnvironmentVariablesRepository implements Repository { } } - const environmentVariable = await this.prismaClient.environmentVariable.findUnique({ + const environmentVariable = await this.prismaClient.environmentVariable.findFirst({ select: { id: true, key: true, @@ -280,7 +280,7 @@ export class EnvironmentVariablesRepository implements Repository { } try { - await $transaction(this.prismaClient, async (tx) => { + await $transaction(this.prismaClient, "edit env var", async (tx) => { const secretStore = getSecretStore("DATABASE", { prismaClient: tx, }); @@ -288,12 +288,10 @@ export class EnvironmentVariablesRepository implements Repository { //create the secret values and references for (const value of values) { const key = secretKey(projectId, value.environmentId, environmentVariable.key); - const existingValue = await tx.environmentVariableValue.findUnique({ + const existingValue = await tx.environmentVariableValue.findFirst({ where: { - variableId_environmentId: { - variableId: environmentVariable.id, - environmentId: value.environmentId, - }, + variableId: environmentVariable.id, + environmentId: value.environmentId, }, }); @@ -356,7 +354,7 @@ export class EnvironmentVariablesRepository implements Repository { } async getProject(projectId: string): Promise { - const project = await this.prismaClient.project.findUnique({ + const project = await this.prismaClient.project.findFirst({ where: { id: projectId, deletedAt: null, @@ -429,7 +427,7 @@ export class EnvironmentVariablesRepository implements Repository { } async getEnvironment(projectId: string, environmentId: string): Promise { - const project = await this.prismaClient.project.findUnique({ + const project = await this.prismaClient.project.findFirst({ where: { id: projectId, deletedAt: null, @@ -483,7 +481,7 @@ export class EnvironmentVariablesRepository implements Repository { } async delete(projectId: string, options: DeleteEnvironmentVariable): Promise { - const project = await this.prismaClient.project.findUnique({ + const project = await this.prismaClient.project.findFirst({ where: { id: projectId, deletedAt: null, @@ -501,7 +499,7 @@ export class EnvironmentVariablesRepository implements Repository { return { success: false as const, error: "Project not found" }; } - const environmentVariable = await this.prismaClient.environmentVariable.findUnique({ + const environmentVariable = await this.prismaClient.environmentVariable.findFirst({ select: { id: true, key: true, @@ -526,7 +524,7 @@ export class EnvironmentVariablesRepository implements Repository { } try { - await $transaction(this.prismaClient, async (tx) => { + await $transaction(this.prismaClient, "delete env var", async (tx) => { await tx.environmentVariable.delete({ where: { id: options.id, @@ -564,7 +562,7 @@ export class EnvironmentVariablesRepository implements Repository { } async deleteValue(projectId: string, options: DeleteEnvironmentVariableValue): Promise { - const project = await this.prismaClient.project.findUnique({ + const project = await this.prismaClient.project.findFirst({ where: { id: projectId, deletedAt: null, @@ -582,7 +580,7 @@ export class EnvironmentVariablesRepository implements Repository { return { success: false as const, error: "Project not found" }; } - const environmentVariable = await this.prismaClient.environmentVariable.findUnique({ + const environmentVariable = await this.prismaClient.environmentVariable.findFirst({ select: { id: true, key: true, @@ -619,7 +617,7 @@ export class EnvironmentVariablesRepository implements Repository { } try { - await $transaction(this.prismaClient, async (tx) => { + await $transaction(this.prismaClient, "delete env var value", async (tx) => { const secretStore = getSecretStore("DATABASE", { prismaClient: tx, }); diff --git a/apps/webapp/app/v3/marqs/devQueueConsumer.server.ts b/apps/webapp/app/v3/marqs/devQueueConsumer.server.ts index a7506f3913..948850410b 100644 --- a/apps/webapp/app/v3/marqs/devQueueConsumer.server.ts +++ b/apps/webapp/app/v3/marqs/devQueueConsumer.server.ts @@ -81,7 +81,7 @@ export class DevQueueConsumer { } public async registerBackgroundWorker(id: string, inProgressRuns: string[] = []) { - const backgroundWorker = await prisma.backgroundWorker.findUnique({ + const backgroundWorker = await prisma.backgroundWorker.findFirst({ where: { friendlyId: id, runtimeEnvironmentId: this.env.id }, include: { tasks: true, @@ -170,7 +170,7 @@ export class DevQueueConsumer { public async taskHeartbeat(workerId: string, id: string) { logger.debug("[DevQueueConsumer] taskHeartbeat()", { id }); - const taskRunAttempt = await prisma.taskRunAttempt.findUnique({ + const taskRunAttempt = await prisma.taskRunAttempt.findFirst({ where: { friendlyId: id }, }); diff --git a/apps/webapp/app/v3/requeueTaskRun.server.ts b/apps/webapp/app/v3/requeueTaskRun.server.ts index 548a7e7d43..5e7732ed35 100644 --- a/apps/webapp/app/v3/requeueTaskRun.server.ts +++ b/apps/webapp/app/v3/requeueTaskRun.server.ts @@ -11,7 +11,7 @@ import { TaskRunErrorCodes } from "@trigger.dev/core/v3"; export class RequeueTaskRunService extends BaseService { public async call(runId: string) { - const taskRun = await this._prisma.taskRun.findUnique({ + const taskRun = await this._prisma.taskRun.findFirst({ where: { id: runId, }, diff --git a/apps/webapp/app/v3/services/alerts/createAlertChannel.server.ts b/apps/webapp/app/v3/services/alerts/createAlertChannel.server.ts index aca1fdd152..edc42d3891 100644 --- a/apps/webapp/app/v3/services/alerts/createAlertChannel.server.ts +++ b/apps/webapp/app/v3/services/alerts/createAlertChannel.server.ts @@ -51,12 +51,10 @@ export class CreateAlertChannelService extends BaseService { : options.environmentTypes; const existingAlertChannel = options.deduplicationKey - ? await this._prisma.projectAlertChannel.findUnique({ + ? await this._prisma.projectAlertChannel.findFirst({ where: { - projectId_deduplicationKey: { - projectId: project.id, - deduplicationKey: options.deduplicationKey, - }, + projectId: project.id, + deduplicationKey: options.deduplicationKey, }, }) : undefined; diff --git a/apps/webapp/app/v3/services/alerts/deliverAlert.server.ts b/apps/webapp/app/v3/services/alerts/deliverAlert.server.ts index 0e7dd87a95..a84388c583 100644 --- a/apps/webapp/app/v3/services/alerts/deliverAlert.server.ts +++ b/apps/webapp/app/v3/services/alerts/deliverAlert.server.ts @@ -547,7 +547,7 @@ export class DeliverAlertService extends BaseService { // Get the org integration const integration = slackProperties.data.integrationId - ? await this._prisma.organizationIntegration.findUnique({ + ? await this._prisma.organizationIntegration.findFirst({ where: { id: slackProperties.data.integrationId, organizationId: alert.project.organizationId, diff --git a/apps/webapp/app/v3/services/alerts/performDeploymentAlerts.server.ts b/apps/webapp/app/v3/services/alerts/performDeploymentAlerts.server.ts index 5c41cf8eac..cd4d20052d 100644 --- a/apps/webapp/app/v3/services/alerts/performDeploymentAlerts.server.ts +++ b/apps/webapp/app/v3/services/alerts/performDeploymentAlerts.server.ts @@ -7,7 +7,7 @@ import { DeliverAlertService } from "./deliverAlert.server"; export class PerformDeploymentAlertsService extends BaseService { public async call(deploymentId: string) { - const deployment = await this._prisma.workerDeployment.findUnique({ + const deployment = await this._prisma.workerDeployment.findFirst({ where: { id: deploymentId }, include: { environment: true, @@ -45,7 +45,7 @@ export class PerformDeploymentAlertsService extends BaseService { deployment: WorkerDeployment, alertType: ProjectAlertType ) { - await $transaction(this._prisma, async (tx) => { + await $transaction(this._prisma, "create and send deploy alert", async (tx) => { const alert = await this._prisma.projectAlert.create({ data: { friendlyId: generateFriendlyId("alert"), diff --git a/apps/webapp/app/v3/services/alerts/performTaskAttemptAlerts.server.ts b/apps/webapp/app/v3/services/alerts/performTaskAttemptAlerts.server.ts index 38486ff4c6..dab6539aeb 100644 --- a/apps/webapp/app/v3/services/alerts/performTaskAttemptAlerts.server.ts +++ b/apps/webapp/app/v3/services/alerts/performTaskAttemptAlerts.server.ts @@ -13,7 +13,7 @@ type FoundTaskAttempt = Prisma.Result< export class PerformTaskAttemptAlertsService extends BaseService { public async call(attemptId: string) { - const taskAttempt = await this._prisma.taskRunAttempt.findUnique({ + const taskAttempt = await this._prisma.taskRunAttempt.findFirst({ where: { id: attemptId }, include: { taskRun: true, @@ -46,7 +46,7 @@ export class PerformTaskAttemptAlertsService extends BaseService { } async #createAndSendAlert(alertChannel: ProjectAlertChannel, taskAttempt: FoundTaskAttempt) { - await $transaction(this._prisma, async (tx) => { + await $transaction(this._prisma, "create and send attempt alert", async (tx) => { const alert = await this._prisma.projectAlert.create({ data: { friendlyId: generateFriendlyId("alert"), diff --git a/apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts b/apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts index 0a5d798be7..1d3b6d62f9 100644 --- a/apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts +++ b/apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts @@ -45,7 +45,7 @@ export class PerformTaskRunAlertsService extends BaseService { } async #createAndSendAlert(alertChannel: ProjectAlertChannel, run: FoundRun) { - await $transaction(this._prisma, async (tx) => { + await $transaction(this._prisma, "create and send run alert", async (tx) => { const alert = await this._prisma.projectAlert.create({ data: { friendlyId: generateFriendlyId("alert"), diff --git a/apps/webapp/app/v3/services/batchTriggerV3.server.ts b/apps/webapp/app/v3/services/batchTriggerV3.server.ts index 197707dfa0..c059597941 100644 --- a/apps/webapp/app/v3/services/batchTriggerV3.server.ts +++ b/apps/webapp/app/v3/services/batchTriggerV3.server.ts @@ -159,7 +159,7 @@ export class BatchTriggerV3Service extends BaseService { span.setAttribute("batchId", batchId); const dependentAttempt = body?.dependentAttempt - ? await this._prisma.taskRunAttempt.findUnique({ + ? await this._prisma.taskRunAttempt.findFirst({ where: { friendlyId: body.dependentAttempt }, include: { taskRun: { @@ -456,7 +456,7 @@ export class BatchTriggerV3Service extends BaseService { return batch; } else { - return await $transaction(this._prisma, async (tx) => { + return await $transaction(this._prisma, "create batch run", async (tx) => { const batch = await tx.batchTaskRun.create({ data: { friendlyId: batchId, @@ -906,7 +906,9 @@ export async function completeBatchTaskRunItemV3( tx: PrismaClientOrTransaction, scheduleResumeOnComplete = false ) { - await $transaction(tx, async (tx) => { + await $transaction(tx, "completeBatchTaskRunItemV3", async (tx, span) => { + span?.setAttribute("batch_id", batchTaskRunId); + // Update the item to complete const updated = await tx.batchTaskRunItem.updateMany({ where: { diff --git a/apps/webapp/app/v3/services/bulk/performBulkAction.server.ts b/apps/webapp/app/v3/services/bulk/performBulkAction.server.ts index 07190cdeb1..dc2a8d11de 100644 --- a/apps/webapp/app/v3/services/bulk/performBulkAction.server.ts +++ b/apps/webapp/app/v3/services/bulk/performBulkAction.server.ts @@ -7,7 +7,7 @@ import { ReplayTaskRunService } from "../replayTaskRun.server"; export class PerformBulkActionService extends BaseService { public async performBulkActionItem(bulkActionItemId: string) { - const item = await this._prisma.bulkActionItem.findUnique({ + const item = await this._prisma.bulkActionItem.findFirst({ where: { id: bulkActionItemId }, include: { group: true, @@ -93,7 +93,7 @@ export class PerformBulkActionService extends BaseService { } public async call(bulkActionGroupId: string) { - const actionGroup = await this._prisma.bulkActionGroup.findUnique({ + const actionGroup = await this._prisma.bulkActionGroup.findFirst({ include: { items: true, }, diff --git a/apps/webapp/app/v3/services/cancelAttempt.server.ts b/apps/webapp/app/v3/services/cancelAttempt.server.ts index 77e99c489a..20f469c81f 100644 --- a/apps/webapp/app/v3/services/cancelAttempt.server.ts +++ b/apps/webapp/app/v3/services/cancelAttempt.server.ts @@ -28,7 +28,7 @@ export class CancelAttemptService extends BaseService { span.setAttribute("taskRunId", taskRunId); span.setAttribute("attemptId", attemptId); - const taskRunAttempt = await this._prisma.taskRunAttempt.findUnique({ + const taskRunAttempt = await this._prisma.taskRunAttempt.findFirst({ where: { friendlyId: attemptId, }, @@ -49,7 +49,7 @@ export class CancelAttemptService extends BaseService { return; } - await $transaction(this._prisma, async (tx) => { + await $transaction(this._prisma, "cancel attempt", async (tx) => { await tx.taskRunAttempt.update({ where: { friendlyId: attemptId, @@ -93,7 +93,7 @@ async function getAuthenticatedEnvironmentFromAttempt( friendlyId: string, prismaClient?: PrismaClientOrTransaction ) { - const taskRunAttempt = await (prismaClient ?? prisma).taskRunAttempt.findUnique({ + const taskRunAttempt = await (prismaClient ?? prisma).taskRunAttempt.findFirst({ where: { friendlyId, }, diff --git a/apps/webapp/app/v3/services/cancelDevSessionRuns.server.ts b/apps/webapp/app/v3/services/cancelDevSessionRuns.server.ts index 040131137d..98fbe762dc 100644 --- a/apps/webapp/app/v3/services/cancelDevSessionRuns.server.ts +++ b/apps/webapp/app/v3/services/cancelDevSessionRuns.server.ts @@ -69,10 +69,10 @@ export class CancelDevSessionRunsService extends BaseService { logger.debug("Cancelling in progress run", { runId }); const taskRun = runId.startsWith("run_") - ? await this._prisma.taskRun.findUnique({ + ? await this._prisma.taskRun.findFirst({ where: { friendlyId: runId }, }) - : await this._prisma.taskRun.findUnique({ + : await this._prisma.taskRun.findFirst({ where: { id: runId }, }); diff --git a/apps/webapp/app/v3/services/cancelTaskAttemptDependencies.server.ts b/apps/webapp/app/v3/services/cancelTaskAttemptDependencies.server.ts index fbe1f1374e..2e14ea1a73 100644 --- a/apps/webapp/app/v3/services/cancelTaskAttemptDependencies.server.ts +++ b/apps/webapp/app/v3/services/cancelTaskAttemptDependencies.server.ts @@ -6,7 +6,7 @@ import { CancelTaskRunService } from "./cancelTaskRun.server"; export class CancelTaskAttemptDependenciesService extends BaseService { public async call(attemptId: string) { - const taskAttempt = await this._prisma.taskRunAttempt.findUnique({ + const taskAttempt = await this._prisma.taskRunAttempt.findFirst({ where: { id: attemptId }, include: { dependencies: { diff --git a/apps/webapp/app/v3/services/completeAttempt.server.ts b/apps/webapp/app/v3/services/completeAttempt.server.ts index 502fc71eea..bae62a37a8 100644 --- a/apps/webapp/app/v3/services/completeAttempt.server.ts +++ b/apps/webapp/app/v3/services/completeAttempt.server.ts @@ -606,7 +606,7 @@ export class CompleteAttemptService extends BaseService { } async #getEnvironment(id: string) { - return await this._prisma.runtimeEnvironment.findUniqueOrThrow({ + return await this._prisma.runtimeEnvironment.findFirstOrThrow({ where: { id, }, @@ -619,7 +619,7 @@ export class CompleteAttemptService extends BaseService { } async function findAttempt(prismaClient: PrismaClientOrTransaction, friendlyId: string) { - return prismaClient.taskRunAttempt.findUnique({ + return prismaClient.taskRunAttempt.findFirst({ where: { friendlyId }, include: { taskRun: true, diff --git a/apps/webapp/app/v3/services/createBackgroundWorker.server.ts b/apps/webapp/app/v3/services/createBackgroundWorker.server.ts index 5cd5e5406c..58c37f463c 100644 --- a/apps/webapp/app/v3/services/createBackgroundWorker.server.ts +++ b/apps/webapp/app/v3/services/createBackgroundWorker.server.ts @@ -27,7 +27,7 @@ export class CreateBackgroundWorkerService extends BaseService { return this.traceWithEnv("call", environment, async (span) => { span.setAttribute("projectRef", projectRef); - const project = await this._prisma.project.findUniqueOrThrow({ + const project = await this._prisma.project.findFirstOrThrow({ where: { externalRef: projectRef, environments: { diff --git a/apps/webapp/app/v3/services/createCheckpoint.server.ts b/apps/webapp/app/v3/services/createCheckpoint.server.ts index 39c62f8858..52492a4fbb 100644 --- a/apps/webapp/app/v3/services/createCheckpoint.server.ts +++ b/apps/webapp/app/v3/services/createCheckpoint.server.ts @@ -30,7 +30,7 @@ export class CreateCheckpointService extends BaseService { > { logger.debug(`Creating checkpoint`, params); - const attempt = await this._prisma.taskRunAttempt.findUnique({ + const attempt = await this._prisma.taskRunAttempt.findFirst({ where: { friendlyId: params.attemptFriendlyId, }, diff --git a/apps/webapp/app/v3/services/createCheckpointRestoreEvent.server.ts b/apps/webapp/app/v3/services/createCheckpointRestoreEvent.server.ts index cb6c753281..1981e0f8e5 100644 --- a/apps/webapp/app/v3/services/createCheckpointRestoreEvent.server.ts +++ b/apps/webapp/app/v3/services/createCheckpointRestoreEvent.server.ts @@ -28,7 +28,7 @@ export class CreateCheckpointRestoreEventService extends BaseService { return; } - const checkpoint = await this._prisma.checkpoint.findUnique({ + const checkpoint = await this._prisma.checkpoint.findFirst({ where: { id: params.checkpointId, }, @@ -44,7 +44,7 @@ export class CreateCheckpointRestoreEventService extends BaseService { let taskRunDependencyId: string | undefined; if (params.dependencyFriendlyRunId) { - const run = await this._prisma.taskRun.findUnique({ + const run = await this._prisma.taskRun.findFirst({ where: { friendlyId: params.dependencyFriendlyRunId, }, diff --git a/apps/webapp/app/v3/services/createDeployedBackgroundWorker.server.ts b/apps/webapp/app/v3/services/createDeployedBackgroundWorker.server.ts index 85c652a38a..11396acaa5 100644 --- a/apps/webapp/app/v3/services/createDeployedBackgroundWorker.server.ts +++ b/apps/webapp/app/v3/services/createDeployedBackgroundWorker.server.ts @@ -23,7 +23,7 @@ export class CreateDeployedBackgroundWorkerService extends BaseService { return this.traceWithEnv("call", environment, async (span) => { span.setAttribute("projectRef", projectRef); - const deployment = await this._prisma.workerDeployment.findUnique({ + const deployment = await this._prisma.workerDeployment.findFirst({ where: { friendlyId: deploymentId, }, diff --git a/apps/webapp/app/v3/services/createDeploymentBackgroundWorker.server.ts b/apps/webapp/app/v3/services/createDeploymentBackgroundWorker.server.ts index cea395510c..826ac841b0 100644 --- a/apps/webapp/app/v3/services/createDeploymentBackgroundWorker.server.ts +++ b/apps/webapp/app/v3/services/createDeploymentBackgroundWorker.server.ts @@ -20,7 +20,7 @@ export class CreateDeploymentBackgroundWorkerService extends BaseService { return this.traceWithEnv("call", environment, async (span) => { span.setAttribute("deploymentId", deploymentId); - const deployment = await this._prisma.workerDeployment.findUnique({ + const deployment = await this._prisma.workerDeployment.findFirst({ where: { friendlyId: deploymentId, }, diff --git a/apps/webapp/app/v3/services/createTaskRunAttempt.server.ts b/apps/webapp/app/v3/services/createTaskRunAttempt.server.ts index 8f2dcc7dcc..c84bc413e3 100644 --- a/apps/webapp/app/v3/services/createTaskRunAttempt.server.ts +++ b/apps/webapp/app/v3/services/createTaskRunAttempt.server.ts @@ -44,7 +44,7 @@ export class CreateTaskRunAttemptService extends BaseService { span.setAttribute("taskRunId", runId); } - const taskRun = await this._prisma.taskRun.findUnique({ + const taskRun = await this._prisma.taskRun.findFirst({ where: { id: !isFriendlyId ? runId : undefined, friendlyId: isFriendlyId ? runId : undefined, @@ -130,7 +130,7 @@ export class CreateTaskRunAttemptService extends BaseService { throw new ServiceValidationError("Max attempts reached", 400); } - const taskRunAttempt = await $transaction(this._prisma, async (tx) => { + const taskRunAttempt = await $transaction(this._prisma, "create attempt", async (tx) => { const taskRunAttempt = await tx.taskRunAttempt.create({ data: { number: nextAttemptNumber, diff --git a/apps/webapp/app/v3/services/deploymentIndexFailed.server.ts b/apps/webapp/app/v3/services/deploymentIndexFailed.server.ts index ef8ac93d61..44b5f55eeb 100644 --- a/apps/webapp/app/v3/services/deploymentIndexFailed.server.ts +++ b/apps/webapp/app/v3/services/deploymentIndexFailed.server.ts @@ -23,7 +23,7 @@ export class DeploymentIndexFailed extends BaseService { ) { const isFriendlyId = maybeFriendlyId.startsWith("deployment_"); - const deployment = await this._prisma.workerDeployment.findUnique({ + const deployment = await this._prisma.workerDeployment.findFirst({ where: isFriendlyId ? { friendlyId: maybeFriendlyId, diff --git a/apps/webapp/app/v3/services/enqueueDelayedRun.server.ts b/apps/webapp/app/v3/services/enqueueDelayedRun.server.ts index c7449eb32b..55db573cc2 100644 --- a/apps/webapp/app/v3/services/enqueueDelayedRun.server.ts +++ b/apps/webapp/app/v3/services/enqueueDelayedRun.server.ts @@ -7,7 +7,7 @@ import { ExpireEnqueuedRunService } from "./expireEnqueuedRun.server"; export class EnqueueDelayedRunService extends BaseService { public async call(runId: string) { - const run = await this._prisma.taskRun.findUnique({ + const run = await this._prisma.taskRun.findFirst({ where: { id: runId, }, @@ -37,7 +37,7 @@ export class EnqueueDelayedRunService extends BaseService { return; } - await $transaction(this._prisma, async (tx) => { + await $transaction(this._prisma, "delayed run enqueue", async (tx) => { await tx.taskRun.update({ where: { id: run.id, diff --git a/apps/webapp/app/v3/services/expireEnqueuedRun.server.ts b/apps/webapp/app/v3/services/expireEnqueuedRun.server.ts index 2ccde4d82d..4834976101 100644 --- a/apps/webapp/app/v3/services/expireEnqueuedRun.server.ts +++ b/apps/webapp/app/v3/services/expireEnqueuedRun.server.ts @@ -19,7 +19,7 @@ export class ExpireEnqueuedRunService extends BaseService { } public async call(runId: string) { - const run = await this._prisma.taskRun.findUnique({ + const run = await this._prisma.taskRun.findFirst({ where: { id: runId, }, diff --git a/apps/webapp/app/v3/services/indexDeployment.server.ts b/apps/webapp/app/v3/services/indexDeployment.server.ts index 0705855a01..2148891996 100644 --- a/apps/webapp/app/v3/services/indexDeployment.server.ts +++ b/apps/webapp/app/v3/services/indexDeployment.server.ts @@ -8,7 +8,7 @@ import { workerQueue } from "~/services/worker.server"; export class IndexDeploymentService extends BaseService { public async call(id: string) { - const deployment = await this._prisma.workerDeployment.findUnique({ + const deployment = await this._prisma.workerDeployment.findFirst({ where: { id, }, diff --git a/apps/webapp/app/v3/services/registerNextTaskScheduleInstance.server.ts b/apps/webapp/app/v3/services/registerNextTaskScheduleInstance.server.ts index fbc77021f5..372811daeb 100644 --- a/apps/webapp/app/v3/services/registerNextTaskScheduleInstance.server.ts +++ b/apps/webapp/app/v3/services/registerNextTaskScheduleInstance.server.ts @@ -1,10 +1,11 @@ +import { startActiveSpan } from "../tracer.server"; import { calculateNextScheduledTimestamp } from "../utils/calculateNextSchedule.server"; import { BaseService } from "./baseService.server"; import { TriggerScheduledTaskService } from "./triggerScheduledTask.server"; export class RegisterNextTaskScheduleInstanceService extends BaseService { public async call(instanceId: string) { - const instance = await this._prisma.taskScheduleInstance.findUnique({ + const instance = await this._prisma.taskScheduleInstance.findFirst({ where: { id: instanceId, }, @@ -18,10 +19,22 @@ export class RegisterNextTaskScheduleInstanceService extends BaseService { return; } - const nextScheduledTimestamp = calculateNextScheduledTimestamp( - instance.taskSchedule.generatorExpression, - instance.taskSchedule.timezone, - instance.lastScheduledTimestamp ?? new Date() + const nextScheduledTimestamp = await startActiveSpan( + "calculateNextScheduledTimestamp", + async (span) => { + span.setAttribute("task_schedule_id", instance.taskSchedule.id); + span.setAttribute("task_schedule_instance_id", instance.id); + span.setAttribute( + "task_schedule_generator_expression", + instance.taskSchedule.generatorExpression + ); + + return calculateNextScheduledTimestamp( + instance.taskSchedule.generatorExpression, + instance.taskSchedule.timezone, + instance.lastScheduledTimestamp ?? new Date() + ); + } ); await this._prisma.taskScheduleInstance.update({ diff --git a/apps/webapp/app/v3/services/rescheduleTaskRun.server.ts b/apps/webapp/app/v3/services/rescheduleTaskRun.server.ts index 4d9461d06b..2d10ba6633 100644 --- a/apps/webapp/app/v3/services/rescheduleTaskRun.server.ts +++ b/apps/webapp/app/v3/services/rescheduleTaskRun.server.ts @@ -17,7 +17,7 @@ export class RescheduleTaskRunService extends BaseService { throw new ServiceValidationError(`Invalid delay: ${body.delay}`); } - return await $transaction(this._prisma, async (tx) => { + return await $transaction(this._prisma, "reschedule run", async (tx) => { const updatedRun = await tx.taskRun.update({ where: { id: taskRun.id, diff --git a/apps/webapp/app/v3/services/restoreCheckpoint.server.ts b/apps/webapp/app/v3/services/restoreCheckpoint.server.ts index a04f46e626..582e6c944f 100644 --- a/apps/webapp/app/v3/services/restoreCheckpoint.server.ts +++ b/apps/webapp/app/v3/services/restoreCheckpoint.server.ts @@ -13,7 +13,7 @@ export class RestoreCheckpointService extends BaseService { }): Promise { logger.debug(`Restoring checkpoint`, params); - const checkpointEvent = await this._prisma.checkpointRestoreEvent.findUnique({ + const checkpointEvent = await this._prisma.checkpointRestoreEvent.findFirst({ where: { id: params.eventId, type: "CHECKPOINT", diff --git a/apps/webapp/app/v3/services/timeoutDeployment.server.ts b/apps/webapp/app/v3/services/timeoutDeployment.server.ts index 20b40341a5..f86f513b18 100644 --- a/apps/webapp/app/v3/services/timeoutDeployment.server.ts +++ b/apps/webapp/app/v3/services/timeoutDeployment.server.ts @@ -6,7 +6,7 @@ import { PrismaClientOrTransaction } from "~/db.server"; export class TimeoutDeploymentService extends BaseService { public async call(id: string, fromStatus: string, errorMessage: string) { - const deployment = await this._prisma.workerDeployment.findUnique({ + const deployment = await this._prisma.workerDeployment.findFirst({ where: { id, }, diff --git a/apps/webapp/app/v3/services/triggerScheduledTask.server.ts b/apps/webapp/app/v3/services/triggerScheduledTask.server.ts index 552043115e..077beb0e2b 100644 --- a/apps/webapp/app/v3/services/triggerScheduledTask.server.ts +++ b/apps/webapp/app/v3/services/triggerScheduledTask.server.ts @@ -12,7 +12,7 @@ export class TriggerScheduledTaskService extends BaseService { public async call(instanceId: string, finalAttempt: boolean) { const registerNextService = new RegisterNextTaskScheduleInstanceService(); - const instance = await this._prisma.taskScheduleInstance.findUnique({ + const instance = await this._prisma.taskScheduleInstance.findFirst({ where: { id: instanceId, }, diff --git a/apps/webapp/app/v3/services/triggerTask.server.ts b/apps/webapp/app/v3/services/triggerTask.server.ts index 264a81827e..7bbb558dbb 100644 --- a/apps/webapp/app/v3/services/triggerTask.server.ts +++ b/apps/webapp/app/v3/services/triggerTask.server.ts @@ -174,7 +174,7 @@ export class TriggerTaskService extends BaseService { : undefined; const dependentAttempt = body.options?.dependentAttempt - ? await this._prisma.taskRunAttempt.findUnique({ + ? await this._prisma.taskRunAttempt.findFirst({ where: { friendlyId: body.options.dependentAttempt }, include: { taskRun: { @@ -211,7 +211,7 @@ export class TriggerTaskService extends BaseService { } const parentAttempt = body.options?.parentAttempt - ? await this._prisma.taskRunAttempt.findUnique({ + ? await this._prisma.taskRunAttempt.findFirst({ where: { friendlyId: body.options.parentAttempt }, include: { taskRun: { @@ -228,7 +228,7 @@ export class TriggerTaskService extends BaseService { : undefined; const dependentBatchRun = body.options?.dependentBatch - ? await this._prisma.batchTaskRun.findUnique({ + ? await this._prisma.batchTaskRun.findFirst({ where: { friendlyId: body.options.dependentBatch }, include: { dependentTaskAttempt: { @@ -272,7 +272,7 @@ export class TriggerTaskService extends BaseService { } const parentBatchRun = body.options?.parentBatch - ? await this._prisma.batchTaskRun.findUnique({ + ? await this._prisma.batchTaskRun.findFirst({ where: { friendlyId: body.options.parentBatch }, include: { dependentTaskAttempt: { @@ -320,13 +320,11 @@ export class TriggerTaskService extends BaseService { `v3-run:${environment.id}:${taskId}`, async (num, tx) => { const lockedToBackgroundWorker = body.options?.lockToVersion - ? await tx.backgroundWorker.findUnique({ + ? await tx.backgroundWorker.findFirst({ where: { - projectId_runtimeEnvironmentId_version: { - projectId: environment.projectId, - runtimeEnvironmentId: environment.id, - version: body.options?.lockToVersion, - }, + projectId: environment.projectId, + runtimeEnvironmentId: environment.id, + version: body.options?.lockToVersion, }, }) : undefined; @@ -669,12 +667,10 @@ export class TriggerTaskService extends BaseService { return defaultQueueName; } - const task = await this._prisma.backgroundWorkerTask.findUnique({ + const task = await this._prisma.backgroundWorkerTask.findFirst({ where: { - workerId_slug: { - workerId: worker.id, - slug: taskId, - }, + workerId: worker.id, + slug: taskId, }, }); diff --git a/apps/webapp/app/v3/services/upsertTaskSchedule.server.ts b/apps/webapp/app/v3/services/upsertTaskSchedule.server.ts index 2d7585e23a..70aa09c2b0 100644 --- a/apps/webapp/app/v3/services/upsertTaskSchedule.server.ts +++ b/apps/webapp/app/v3/services/upsertTaskSchedule.server.ts @@ -37,17 +37,15 @@ export class UpsertTaskScheduleService extends BaseService { : nanoid(24); const existingSchedule = schedule.friendlyId - ? await this._prisma.taskSchedule.findUnique({ + ? await this._prisma.taskSchedule.findFirst({ where: { friendlyId: schedule.friendlyId, }, }) - : await this._prisma.taskSchedule.findUnique({ + : await this._prisma.taskSchedule.findFirst({ where: { - projectId_deduplicationKey: { - projectId, - deduplicationKey, - }, + projectId, + deduplicationKey, }, }); @@ -94,50 +92,54 @@ export class UpsertTaskScheduleService extends BaseService { projectId: string, deduplicationKey: string ) { - return await $transaction(this._prisma, async (tx) => { - const scheduleRecord = await tx.taskSchedule.create({ - data: { - projectId, - friendlyId: generateFriendlyId("sched"), - taskIdentifier: options.taskIdentifier, - deduplicationKey, - userProvidedDeduplicationKey: - options.deduplicationKey !== undefined && options.deduplicationKey !== "", - generatorExpression: options.cron, - generatorDescription: cronstrue.toString(options.cron), - timezone: options.timezone ?? "UTC", - externalId: options.externalId ? options.externalId : undefined, - }, - }); + return await $transaction( + this._prisma, + "UpsertTaskSchedule.upsertNewSchedule", + async (tx, span) => { + const scheduleRecord = await tx.taskSchedule.create({ + data: { + projectId, + friendlyId: generateFriendlyId("sched"), + taskIdentifier: options.taskIdentifier, + deduplicationKey, + userProvidedDeduplicationKey: + options.deduplicationKey !== undefined && options.deduplicationKey !== "", + generatorExpression: options.cron, + generatorDescription: cronstrue.toString(options.cron), + timezone: options.timezone ?? "UTC", + externalId: options.externalId ? options.externalId : undefined, + }, + }); - const registerNextService = new RegisterNextTaskScheduleInstanceService(tx); + const registerNextService = new RegisterNextTaskScheduleInstanceService(tx); - //create the instances (links to environments) + //create the instances (links to environments) - for (const environmentId of options.environments) { - const instance = await tx.taskScheduleInstance.create({ - data: { - taskScheduleId: scheduleRecord.id, - environmentId, - }, - include: { - environment: { - include: { - orgMember: { - include: { - user: true, + for (const environmentId of options.environments) { + const instance = await tx.taskScheduleInstance.create({ + data: { + taskScheduleId: scheduleRecord.id, + environmentId, + }, + include: { + environment: { + include: { + orgMember: { + include: { + user: true, + }, }, }, }, }, - }, - }); + }); - await registerNextService.call(instance.id); - } + await registerNextService.call(instance.id); + } - return { scheduleRecord }; - }); + return { scheduleRecord }; + } + ); } async #updateExistingSchedule( diff --git a/internal-packages/database/prisma/migrations/20250203132941_add_missing_batch_task_run_dependent_task_attempt_id_index/migration.sql b/internal-packages/database/prisma/migrations/20250203132941_add_missing_batch_task_run_dependent_task_attempt_id_index/migration.sql new file mode 100644 index 0000000000..579862754f --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250203132941_add_missing_batch_task_run_dependent_task_attempt_id_index/migration.sql @@ -0,0 +1,2 @@ +-- CreateIndex +CREATE INDEX CONCURRENTLY IF NOT EXISTS "BatchTaskRun_dependentTaskAttemptId_idx" ON "BatchTaskRun"("dependentTaskAttemptId"); \ No newline at end of file diff --git a/internal-packages/database/prisma/migrations/20250203133220_add_missing_checkpoint_restore_event_checkpoint_id_index/migration.sql b/internal-packages/database/prisma/migrations/20250203133220_add_missing_checkpoint_restore_event_checkpoint_id_index/migration.sql new file mode 100644 index 0000000000..125725c6e0 --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250203133220_add_missing_checkpoint_restore_event_checkpoint_id_index/migration.sql @@ -0,0 +1,2 @@ +-- CreateIndex +CREATE INDEX CONCURRENTLY IF NOT EXISTS "CheckpointRestoreEvent_checkpointId_idx" ON "CheckpointRestoreEvent"("checkpointId"); \ No newline at end of file diff --git a/internal-packages/database/prisma/migrations/20250203133324_add_missing_checkpoint_restore_event_run_id_index/migration.sql b/internal-packages/database/prisma/migrations/20250203133324_add_missing_checkpoint_restore_event_run_id_index/migration.sql new file mode 100644 index 0000000000..bc2da5f2b1 --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250203133324_add_missing_checkpoint_restore_event_run_id_index/migration.sql @@ -0,0 +1,2 @@ +-- CreateIndex +CREATE INDEX CONCURRENTLY IF NOT EXISTS "CheckpointRestoreEvent_runId_idx" ON "CheckpointRestoreEvent"("runId"); \ No newline at end of file diff --git a/internal-packages/database/prisma/migrations/20250203133511_add_missing_task_run_dependency_dependent_attempt_id_index/migration.sql b/internal-packages/database/prisma/migrations/20250203133511_add_missing_task_run_dependency_dependent_attempt_id_index/migration.sql new file mode 100644 index 0000000000..a7d5f8a4ba --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250203133511_add_missing_task_run_dependency_dependent_attempt_id_index/migration.sql @@ -0,0 +1,2 @@ +-- CreateIndex +CREATE INDEX CONCURRENTLY IF NOT EXISTS "TaskRunDependency_dependentAttemptId_idx" ON "TaskRunDependency"("dependentAttemptId"); \ No newline at end of file diff --git a/internal-packages/database/prisma/migrations/20250203133619_add_missing_task_run_dependency_dependent_batch_run_id_index/migration.sql b/internal-packages/database/prisma/migrations/20250203133619_add_missing_task_run_dependency_dependent_batch_run_id_index/migration.sql new file mode 100644 index 0000000000..8389ba833b --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250203133619_add_missing_task_run_dependency_dependent_batch_run_id_index/migration.sql @@ -0,0 +1,2 @@ +-- CreateIndex +CREATE INDEX CONCURRENTLY IF NOT EXISTS "TaskRunDependency_dependentBatchRunId_idx" ON "TaskRunDependency"("dependentBatchRunId"); \ No newline at end of file diff --git a/internal-packages/database/prisma/migrations/20250203133835_add_missing_background_worker_runtime_environment_id_index/migration.sql b/internal-packages/database/prisma/migrations/20250203133835_add_missing_background_worker_runtime_environment_id_index/migration.sql new file mode 100644 index 0000000000..0d43d29c96 --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250203133835_add_missing_background_worker_runtime_environment_id_index/migration.sql @@ -0,0 +1,2 @@ +-- CreateIndex +CREATE INDEX CONCURRENTLY IF NOT EXISTS "BackgroundWorker_runtimeEnvironmentId_idx" ON "BackgroundWorker"("runtimeEnvironmentId"); \ No newline at end of file diff --git a/internal-packages/database/prisma/migrations/20250203134009_add_missing_background_worker_task_runtime_environment_id_project_id_index/migration.sql b/internal-packages/database/prisma/migrations/20250203134009_add_missing_background_worker_task_runtime_environment_id_project_id_index/migration.sql new file mode 100644 index 0000000000..a50e4a767e --- /dev/null +++ b/internal-packages/database/prisma/migrations/20250203134009_add_missing_background_worker_task_runtime_environment_id_project_id_index/migration.sql @@ -0,0 +1,2 @@ +-- CreateIndex +CREATE INDEX CONCURRENTLY IF NOT EXISTS "BackgroundWorkerTask_runtimeEnvironmentId_projectId_idx" ON "BackgroundWorkerTask"("runtimeEnvironmentId", "projectId"); \ No newline at end of file diff --git a/internal-packages/database/prisma/schema.prisma b/internal-packages/database/prisma/schema.prisma index ef36eb7818..8cd37c9077 100644 --- a/internal-packages/database/prisma/schema.prisma +++ b/internal-packages/database/prisma/schema.prisma @@ -1583,6 +1583,7 @@ model BackgroundWorker { supportsLazyAttempts Boolean @default(false) @@unique([projectId, runtimeEnvironmentId, version]) + @@index([runtimeEnvironmentId]) } model BackgroundWorkerFile { @@ -1646,6 +1647,7 @@ model BackgroundWorkerTask { @@unique([workerId, slug]) // Quick lookup of task identifiers @@index([projectId, slug]) + @@index([runtimeEnvironmentId, projectId]) } enum TaskTriggerSource { @@ -1912,6 +1914,9 @@ model TaskRunDependency { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt + + @@index([dependentAttemptId]) + @@index([dependentBatchRunId]) } /// deprecated, we hadn't included the project id in the unique constraint @@ -2196,6 +2201,7 @@ model BatchTaskRun { @@unique([oneTimeUseToken]) ///this is used for all engine versions @@unique([runtimeEnvironmentId, idempotencyKey]) + @@index([dependentTaskAttemptId]) } enum BatchTaskRunStatus { @@ -2325,6 +2331,9 @@ model CheckpointRestoreEvent { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt + + @@index([checkpointId]) + @@index([runId]) } enum CheckpointRestoreEventType {