Skip to content
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
6 changes: 3 additions & 3 deletions apps/webapp/app/models/project.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { nanoid, customAlphabet } from "nanoid";
import slug from "slug";
import { prisma } from "~/db.server";
import { $replica, prisma } from "~/db.server";
import type { Project } from "@trigger.dev/database";
import { Organization, createEnvironment } from "./organization.server";
import { env } from "~/env.server";
Expand Down Expand Up @@ -135,7 +135,7 @@ export async function createProject(

export async function findProjectBySlug(orgSlug: string, projectSlug: string, userId: string) {
// Find the project scoped to the organization, making sure the user belongs to that org
return await prisma.project.findFirst({
return await $replica.project.findFirst({
where: {
slug: projectSlug,
organization: {
Expand All @@ -148,7 +148,7 @@ export async function findProjectBySlug(orgSlug: string, projectSlug: string, us

export async function findProjectByRef(externalRef: string, userId: string) {
// Find the project scoped to the organization, making sure the user belongs to that org
return await prisma.project.findFirst({
return await $replica.project.findFirst({
where: {
externalRef,
organization: {
Expand Down
16 changes: 8 additions & 8 deletions apps/webapp/app/models/runtimeEnvironment.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AuthenticatedEnvironment } from "@internal/run-engine";
import type { Prisma, PrismaClientOrTransaction, RuntimeEnvironment } from "@trigger.dev/database";
import { prisma } from "~/db.server";
import { $replica, prisma } from "~/db.server";
import { logger } from "~/services/logger.server";
import { getUsername } from "~/utils/username";
import { sanitizeBranchName } from "~/v3/gitBranch";
Expand All @@ -11,7 +11,7 @@ export async function findEnvironmentByApiKey(
apiKey: string,
branchName: string | undefined
): Promise<AuthenticatedEnvironment | null> {
const environment = await prisma.runtimeEnvironment.findFirst({
const environment = await $replica.runtimeEnvironment.findFirst({
where: {
apiKey,
},
Expand Down Expand Up @@ -67,7 +67,7 @@ export async function findEnvironmentByPublicApiKey(
apiKey: string,
branchName: string | undefined
): Promise<AuthenticatedEnvironment | null> {
const environment = await prisma.runtimeEnvironment.findFirst({
const environment = await $replica.runtimeEnvironment.findFirst({
where: {
pkApiKey: apiKey,
},
Expand All @@ -89,7 +89,7 @@ export async function findEnvironmentByPublicApiKey(
export async function findEnvironmentById(
id: string
): Promise<(AuthenticatedEnvironment & { parentEnvironment: { apiKey: string } | null }) | null> {
const environment = await prisma.runtimeEnvironment.findFirst({
const environment = await $replica.runtimeEnvironment.findFirst({
where: {
id,
},
Expand Down Expand Up @@ -118,7 +118,7 @@ export async function findEnvironmentBySlug(
envSlug: string,
userId: string
): Promise<AuthenticatedEnvironment | null> {
return prisma.runtimeEnvironment.findFirst({
return $replica.runtimeEnvironment.findFirst({
where: {
projectId: projectId,
slug: envSlug,
Expand Down Expand Up @@ -148,7 +148,7 @@ export async function findEnvironmentFromRun(
runId: string,
tx?: PrismaClientOrTransaction
): Promise<AuthenticatedEnvironment | null> {
const taskRun = await (tx ?? prisma).taskRun.findFirst({
const taskRun = await (tx ?? $replica).taskRun.findFirst({
where: {
id: runId,
},
Expand Down Expand Up @@ -223,7 +223,7 @@ export async function disconnectSession(environmentId: string) {
}

export async function findLatestSession(environmentId: string) {
const session = await prisma.runtimeEnvironmentSession.findFirst({
const session = await $replica.runtimeEnvironmentSession.findFirst({
where: {
environmentId,
},
Expand Down Expand Up @@ -280,7 +280,7 @@ export async function findDisplayableEnvironment(
environmentId: string,
userId: string | undefined
) {
const environment = await prisma.runtimeEnvironment.findFirst({
const environment = await $replica.runtimeEnvironment.findFirst({
where: {
id: environmentId,
},
Expand Down
16 changes: 8 additions & 8 deletions apps/webapp/app/services/apiAuth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type Prettify } from "@trigger.dev/core";
import { SignJWT, errors, jwtVerify } from "jose";
import { z } from "zod";

import { prisma } from "~/db.server";
import { $replica } from "~/db.server";
import { env } from "~/env.server";
import { findProjectByRef } from "~/models/project.server";
import {
Expand Down Expand Up @@ -479,7 +479,7 @@ export async function authenticatedEnvironmentForAuthentication(
return auth.result.environment;
}
case "personalAccessToken": {
const user = await prisma.user.findUnique({
const user = await $replica.user.findUnique({
where: {
id: auth.result.userId,
},
Expand All @@ -498,7 +498,7 @@ export async function authenticatedEnvironmentForAuthentication(
const sanitizedBranch = sanitizeBranchName(branch);

if (!sanitizedBranch) {
const environment = await prisma.runtimeEnvironment.findFirst({
const environment = await $replica.runtimeEnvironment.findFirst({
where: {
projectId: project.id,
slug: slug,
Expand All @@ -523,7 +523,7 @@ export async function authenticatedEnvironmentForAuthentication(
return environment;
}

const environment = await prisma.runtimeEnvironment.findFirst({
const environment = await $replica.runtimeEnvironment.findFirst({
where: {
projectId: project.id,
type: "PREVIEW",
Expand Down Expand Up @@ -553,7 +553,7 @@ export async function authenticatedEnvironmentForAuthentication(
};
}
case "organizationAccessToken": {
const organization = await prisma.organization.findUnique({
const organization = await $replica.organization.findUnique({
where: {
id: auth.result.organizationId,
},
Expand All @@ -563,7 +563,7 @@ export async function authenticatedEnvironmentForAuthentication(
throw json({ error: "Invalid or missing organization access token" }, { status: 401 });
}

const project = await prisma.project.findFirst({
const project = await $replica.project.findFirst({
where: {
organizationId: organization.id,
externalRef: projectRef,
Expand All @@ -577,7 +577,7 @@ export async function authenticatedEnvironmentForAuthentication(
const sanitizedBranch = sanitizeBranchName(branch);

if (!sanitizedBranch) {
const environment = await prisma.runtimeEnvironment.findFirst({
const environment = await $replica.runtimeEnvironment.findFirst({
where: {
projectId: project.id,
slug: slug,
Expand All @@ -595,7 +595,7 @@ export async function authenticatedEnvironmentForAuthentication(
return environment;
}

const environment = await prisma.runtimeEnvironment.findFirst({
const environment = await $replica.runtimeEnvironment.findFirst({
where: {
projectId: project.id,
type: "PREVIEW",
Expand Down