11import type { AuthenticatedEnvironment } from "@internal/run-engine" ;
22import type { Prisma , PrismaClientOrTransaction , RuntimeEnvironment } from "@trigger.dev/database" ;
3- import { prisma } from "~/db.server" ;
3+ import { $replica , prisma } from "~/db.server" ;
44import { logger } from "~/services/logger.server" ;
55import { getUsername } from "~/utils/username" ;
66import { sanitizeBranchName } from "~/v3/gitBranch" ;
@@ -11,7 +11,7 @@ export async function findEnvironmentByApiKey(
1111 apiKey : string ,
1212 branchName : string | undefined
1313) : Promise < AuthenticatedEnvironment | null > {
14- const environment = await prisma . runtimeEnvironment . findFirst ( {
14+ const environment = await $replica . runtimeEnvironment . findFirst ( {
1515 where : {
1616 apiKey,
1717 } ,
@@ -67,7 +67,7 @@ export async function findEnvironmentByPublicApiKey(
6767 apiKey : string ,
6868 branchName : string | undefined
6969) : Promise < AuthenticatedEnvironment | null > {
70- const environment = await prisma . runtimeEnvironment . findFirst ( {
70+ const environment = await $replica . runtimeEnvironment . findFirst ( {
7171 where : {
7272 pkApiKey : apiKey ,
7373 } ,
@@ -89,7 +89,7 @@ export async function findEnvironmentByPublicApiKey(
8989export async function findEnvironmentById (
9090 id : string
9191) : Promise < ( AuthenticatedEnvironment & { parentEnvironment : { apiKey : string } | null } ) | null > {
92- const environment = await prisma . runtimeEnvironment . findFirst ( {
92+ const environment = await $replica . runtimeEnvironment . findFirst ( {
9393 where : {
9494 id,
9595 } ,
@@ -118,7 +118,7 @@ export async function findEnvironmentBySlug(
118118 envSlug : string ,
119119 userId : string
120120) : Promise < AuthenticatedEnvironment | null > {
121- return prisma . runtimeEnvironment . findFirst ( {
121+ return $replica . runtimeEnvironment . findFirst ( {
122122 where : {
123123 projectId : projectId ,
124124 slug : envSlug ,
@@ -148,7 +148,7 @@ export async function findEnvironmentFromRun(
148148 runId : string ,
149149 tx ?: PrismaClientOrTransaction
150150) : Promise < AuthenticatedEnvironment | null > {
151- const taskRun = await ( tx ?? prisma ) . taskRun . findFirst ( {
151+ const taskRun = await ( tx ?? $replica ) . taskRun . findFirst ( {
152152 where : {
153153 id : runId ,
154154 } ,
@@ -223,7 +223,7 @@ export async function disconnectSession(environmentId: string) {
223223}
224224
225225export async function findLatestSession ( environmentId : string ) {
226- const session = await prisma . runtimeEnvironmentSession . findFirst ( {
226+ const session = await $replica . runtimeEnvironmentSession . findFirst ( {
227227 where : {
228228 environmentId,
229229 } ,
@@ -280,7 +280,7 @@ export async function findDisplayableEnvironment(
280280 environmentId : string ,
281281 userId : string | undefined
282282) {
283- const environment = await prisma . runtimeEnvironment . findFirst ( {
283+ const environment = await $replica . runtimeEnvironment . findFirst ( {
284284 where : {
285285 id : environmentId ,
286286 } ,
0 commit comments