Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: bulk create inventory jobs

Brad Barbinc91513ad9894
diff --git a/apps/erp/app/modules/production/production.models.ts b/apps/erp/app/modules/production/production.models.ts
index 4380164748..869ecaa294 100644
--- a/apps/erp/app/modules/production/production.models.ts
+++ b/apps/erp/app/modules/production/production.models.ts
@@ -76,6 +76,62 @@ const baseJobValidator = z.object({
configuration: z.any().optional(),
});
+export const bulkJobValidator = z
+ .object({
+ itemId: z.string().min(1, { message: "Item is required" }),
+ totalQuantity: zfd.numeric(z.number().min(0)),
+ quantityPerJob: zfd.numeric(z.number().min(0)),
+ scrapQuantityPerJob: zfd.numeric(z.number().min(0)),
+ unitOfMeasureCode: z
+ .string()
+ .min(1, { message: "Unit of measure is required" }),
+ deadlineType: z.enum(deadlineTypes, {
+ errorMap: () => ({ message: "Deadline type is required" }),
+ }),
+ dueDateOfFirstJob: zfd.text(z.string().optional()),
+ dueDateOfLastJob: zfd.text(z.string().optional()),
+ locationId: z.string().min(1, { message: "Location is required" }),
+ customerId: zfd.text(z.string().optional()),
+ modelUploadId: zfd.text(z.string().optional()),
+ configuration: z.any().optional(),
+ })
+ .refine(
+ (data) => {
+ if (data.dueDateOfFirstJob && data.dueDateOfLastJob) {
+ return data.dueDateOfFirstJob <= data.dueDateOfLastJob;
+ }
+ return true;
+ },
+ {
+ message: "Due date of first job must be before due date of last job",
+ path: ["dueDateOfLastJob"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (["Hard Deadline", "Soft Deadline"].includes(data.deadlineType)) {
+ return !!data.dueDateOfFirstJob;
+ }
+ return true;
+ },
+ {
+ message: "Due date of first job is required for hard and soft deadlines",
+ path: ["dueDateOfFirstJob"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (["Hard Deadline", "Soft Deadline"].includes(data.deadlineType)) {
+ return !!data.dueDateOfLastJob;
+ }
+ return true;
+ },
+ {
+ message: "Due date of last job is required for hard and soft deadlines",
+ path: ["dueDateOfLastJob"],
+ }
+ );
+
export const jobValidator = baseJobValidator.refine(
(data) => {
if (
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobForm.tsx b/apps/erp/app/modules/production/ui/Jobs/JobForm.tsx
index 426c9f58a9..9e0d55c5c8 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobForm.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobForm.tsx
@@ -8,6 +8,10 @@ import {
CardFooter,
CardHeader,
CardTitle,
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
VStack,
cn,
toast,
@@ -36,8 +40,13 @@ import type {
ConfigurationParameterGroup,
} from "~/modules/items/types";
import { type MethodItemType } from "~/modules/shared";
+import { path } from "~/utils/path";
import type { jobStatus } from "../../production.models";
-import { deadlineTypes, jobValidator } from "../../production.models";
+import {
+ bulkJobValidator,
+ deadlineTypes,
+ jobValidator,
+} from "../../production.models";
import { getDeadlineIcon, getDeadlineText } from "./Deadline";
type JobFormValues = z.infer<typeof jobValidator> & {
@@ -62,11 +71,25 @@ const JobForm = ({ initialValues }: JobFormProps) => {
initialValues.status ?? ""
);
+ const bulkInitialValues = {
+ ...initialValues,
+ totalQuantity: initialValues.quantity ?? 0,
+ quantityPerJob: initialValues.quantity ?? 1,
+ scrapQuantityPerJob: initialValues.scrapQuantity ?? 0,
+ dueDateOfFirstJob: initialValues.dueDate ?? "",
+ dueDateOfLastJob: initialValues.dueDate ?? "",
+ locationId: initialValues.locationId ?? "",
+ customerId: initialValues.customerId ?? "",
+ modelUploadId: initialValues.modelUploadId ?? "",
+ configuration: initialValues.configuration ?? {},
+ };
+
const [itemData, setItemData] = useState<{
itemId: string;
description: string;
uom: string;
quantity: number;
+ quantityPerJob: number;
scrapQuantity: number;
scrapPercentage: number;
modelUploadId: string | null;
@@ -74,6 +97,7 @@ const JobForm = ({ initialValues }: JobFormProps) => {
itemId: initialValues.itemId ?? "",
description: initialValues.description ?? "",
quantity: initialValues.quantity ?? 0,
+ quantityPerJob: initialValues.quantity ?? 1,
scrapQuantity: initialValues.scrapQuantity ?? 0,
scrapPercentage:
(initialValues.quantity ?? 0) === 0
@@ -103,7 +127,8 @@ const JobForm = ({ initialValues }: JobFormProps) => {
itemId: "",
description: "",
uom: "EA",
- quantity: 0,
+ quantity: 1,
+ quantityPerJob: 1,
scrapPercentage: 0,
scrapQuantity: 0,
modelUploadId: null,
@@ -142,6 +167,10 @@ const JobForm = ({ initialValues }: JobFormProps) => {
(manufacturing?.data?.lotSize ?? 0) === 0
? current.quantity
: manufacturing?.data?.lotSize ?? 0,
+ quantityPerJob:
+ (manufacturing?.data?.lotSize ?? 0) === 0
+ ? current.quantityPerJob
+ : manufacturing?.data?.lotSize ?? 0,
modelUploadId: item.data?.modelUploadId ?? null,
scrapPercentage: manufacturing?.data?.scrapPercentage ?? 0,
scrapQuantity: Math.ceil(
@@ -186,161 +215,350 @@ const JobForm = ({ initialValues }: JobFormProps) => {
return (
<>
- <Card>
- <ValidatedForm
- method="post"
- validator={jobValidator}
- defaultValues={initialValues}
- >
- <CardHeader>
- <CardTitle>{isEditing ? "Job" : "New Job"}</CardTitle>
- {!isEditing && (
- <CardDescription>
- A job is a set of work to be done to fulfill an order or
- increase inventory
- </CardDescription>
- )}
- </CardHeader>
- <CardContent>
- <Hidden name="id" />
- <Hidden
- name="modelUploadId"
- value={itemData.modelUploadId ?? undefined}
- />
- {!isEditing && requiresConfiguration && (
- <Hidden
- name="configuration"
- value={JSON.stringify(configurationValues)}
- />
- )}
- <VStack>
- <div
- className={cn(
- "grid w-full gap-x-8 gap-y-4",
- isEditing
- ? "grid-cols-1 lg:grid-cols-3"
- : "grid-cols-1 md:grid-cols-2"
- )}
+ <Tabs defaultValue="job">
+ <VStack className="w-full items-center">
+ {!isEditing && (
+ <TabsList className="bg-background/30">
+ <TabsTrigger value="job">Single Job</TabsTrigger>
+ <TabsTrigger value="bulk">Many Jobs</TabsTrigger>
+ </TabsList>
+ )}
+
+ <TabsContent value="job" className="w-full">
+ <Card>
+ <ValidatedForm
+ method="post"
+ validator={jobValidator}
+ defaultValues={initialValues}
>
- {isEditing ? (
- <Input name="jobId" label="Job ID" isReadOnly />
- ) : (
- <SequenceOrCustomId name="jobId" label="Job ID" table="job" />
- )}
-
- <Item
- name="itemId"
- label={type}
- type={type}
- value={itemData.itemId}
- validItemTypes={["Part", "Tool"]}
- onChange={(value) => {
- onItemChange(value?.value as string);
- }}
- onTypeChange={onTypeChange}
- />
-
- {isEditing && (
- <InputControlled
- name="description"
- label="Short Description"
- value={itemData.description}
- isReadOnly
+ <CardHeader>
+ <CardTitle>{isEditing ? "Job" : "New Job"}</CardTitle>
+ {!isEditing && (
+ <CardDescription>
+ A job is a set of work to be done to fulfill an order or
+ increase inventory
+ </CardDescription>
+ )}
+ </CardHeader>
+ <CardContent>
+ <Hidden name="id" />
+ <Hidden
+ name="modelUploadId"
+ value={itemData.modelUploadId ?? undefined}
/>
- )}
-
- <NumberControlled
- name="quantity"
- label="Quantity"
- value={itemData.quantity}
- onChange={(value) =>
- setItemData((prev) => ({
- ...prev,
- quantity: value,
- scrapQuantity: Math.ceil(value * prev.scrapPercentage),
- }))
- }
- minValue={0}
- />
- <NumberControlled
- name="scrapQuantity"
- label="Scrap Quantity"
- value={itemData.scrapQuantity}
- onChange={(value) =>
- setItemData((prev) => ({
- ...prev,
- scrapQuantity: value,
- scrapPercentage:
- prev.quantity > 0 ? value / prev.quantity : 1,
- }))
- }
- minValue={0}
- />
-
- <UnitOfMeasure
- name="unitOfMeasureCode"
- value={itemData.uom}
- onChange={(value) => {
- if (value?.value) {
- setItemData((prev) => ({ ...prev, uom: value.value }));
+ {!isEditing && requiresConfiguration && (
+ <Hidden
+ name="configuration"
+ value={JSON.stringify(configurationValues)}
+ />
+ )}
+ <VStack>
+ <div
+ className={cn(
+ "grid w-full gap-x-8 gap-y-4",
+ isEditing
+ ? "grid-cols-1 lg:grid-cols-3"
+ : "grid-cols-1 md:grid-cols-2"
+ )}
+ >
+ {isEditing ? (
+ <Input name="jobId" label="Job ID" isReadOnly />
+ ) : (
+ <SequenceOrCustomId
+ name="jobId"
+ label="Job ID"
+ table="job"
+ />
+ )}
+
+ <Item
+ name="itemId"
+ label={type}
+ type={type}
+ value={itemData.itemId}
+ validItemTypes={["Part", "Tool"]}
+ onChange={(value) => {
+ onItemChange(value?.value as string);
+ }}
+ onTypeChange={onTypeChange}
+ />
+
+ {isEditing && (
+ <InputControlled
+ name="description"
+ label="Short Description"
+ value={itemData.description}
+ isReadOnly
+ />
+ )}
+
+ <NumberControlled
+ name="quantity"
+ label="Quantity"
+ value={itemData.quantity}
+ onChange={(value) =>
+ setItemData((prev) => ({
+ ...prev,
+ quantity: value,
+ scrapQuantity: Math.ceil(
+ value * prev.scrapPercentage
+ ),
+ }))
+ }
+ minValue={0}
+ />
+ <NumberControlled
+ name="scrapQuantity"
+ label="Scrap Quantity"
+ value={itemData.scrapQuantity}
+ onChange={(value) =>
+ setItemData((prev) => ({
+ ...prev,
+ scrapQuantity: value,
+ scrapPercentage:
+ prev.quantity > 0 ? value / prev.quantity : 1,
+ }))
+ }
+ minValue={0}
+ />
+
+ <UnitOfMeasure
+ name="unitOfMeasureCode"
+ value={itemData.uom}
+ onChange={(value) => {
+ if (value?.value) {
+ setItemData((prev) => ({
+ ...prev,
+ uom: value.value,
+ }));
+ }
+ }}
+ />
+ <Location name="locationId" label="Location" />
+
+ <DatePicker
+ name="dueDate"
+ label="Due Date"
+ isDisabled={isCustomer}
+ />
+ <Select
+ name="deadlineType"
+ label="Deadline Type"
+ options={deadlineTypes.map((d) => ({
+ value: d,
+ label: (
+ <div className="flex gap-1 items-center">
+ {getDeadlineIcon(d, false)}
+ <span>{getDeadlineText(d)}</span>
+ </div>
+ ),
+ }))}
+ />
+
+ {isEditing && (
+ <Customer
+ name="customerId"
+ label="Customer"
+ isOptional
+ />
+ )}
+
+ <CustomFormFields table="job" />
+ </div>
+ </VStack>
+ </CardContent>
+ <CardFooter>
+ {!isEditing && requiresConfiguration && (
+ <Button
+ type="button"
+ variant={isConfigured ? "secondary" : "primary"}
+ onClick={() => {
+ configurationDisclosure.onOpen();
+ }}
+ >
+ Configure
+ </Button>
+ )}
+ <Submit
+ isDisabled={
+ (requiresConfiguration && !isConfigured) ||
+ isDisabled ||
+ (isEditing
+ ? !permissions.can("update", "production")
+ : !permissions.can("create", "production"))
}
- }}
- />
- <Location name="locationId" label="Location" />
-
- <DatePicker
- name="dueDate"
- label="Due Date"
- isDisabled={isCustomer}
- />
- <Select
- name="deadlineType"
- label="Deadline Type"
- options={deadlineTypes.map((d) => ({
- value: d,
- label: (
- <div className="flex gap-1 items-center">
- {getDeadlineIcon(d, false)}
- <span>{getDeadlineText(d)}</span>
+ >
+ Save
+ </Submit>
+ </CardFooter>
+ </ValidatedForm>
+ </Card>
+ </TabsContent>
+ {!isEditing && (
+ <TabsContent value="bulk" className="w-full">
+ <Card>
+ <ValidatedForm
+ method="post"
+ action={path.to.newBulkJob}
+ validator={bulkJobValidator}
+ defaultValues={bulkInitialValues}
+ >
+ <CardHeader>
+ <CardTitle>Bulk Jobs</CardTitle>
+ <CardDescription>
+ The bulk jobs form creates multiple jobs for the same item
+ across multiple due dates.
+ </CardDescription>
+ </CardHeader>
+ <CardContent>
+ <Hidden name="id" />
+ <Hidden
+ name="modelUploadId"
+ value={itemData.modelUploadId ?? undefined}
+ />
+ {!isEditing && requiresConfiguration && (
+ <Hidden
+ name="configuration"
+ value={JSON.stringify(configurationValues)}
+ />
+ )}
+ <VStack>
+ <div
+ className={cn(
+ "grid w-full gap-x-8 gap-y-4",
+ "grid-cols-1 md:grid-cols-2"
+ )}
+ >
+ <Item
+ name="itemId"
+ label={type}
+ type={type}
+ value={itemData.itemId}
+ validItemTypes={["Part", "Tool"]}
+ onChange={(value) => {
+ onItemChange(value?.value as string);
+ }}
+ onTypeChange={onTypeChange}
+ />
+
+ <NumberControlled
+ name="totalQuantity"
+ label="Total Quantity"
+ value={itemData.quantity}
+ onChange={(value) =>
+ setItemData((prev) => ({
+ ...prev,
+ quantity: value,
+ }))
+ }
+ minValue={0}
+ />
+
+ <NumberControlled
+ name="quantityPerJob"
+ label="Quantity Per Job"
+ value={itemData.quantityPerJob}
+ onChange={(value) =>
+ setItemData((prev) => ({
+ ...prev,
+ quantityPerJob: value,
+ }))
+ }
+ minValue={0}
+ />
+
+ <NumberControlled
+ name="scrapQuantityPerJob"
+ label="Scrap Quantity Per Job"
+ value={itemData.scrapQuantity}
+ onChange={(value) =>
+ setItemData((prev) => ({
+ ...prev,
+ scrapQuantity: value,
+ }))
+ }
+ minValue={0}
+ />
+
+ <UnitOfMeasure
+ name="unitOfMeasureCode"
+ value={itemData.uom}
+ onChange={(value) => {
+ if (value?.value) {
+ setItemData((prev) => ({
+ ...prev,
+ uom: value.value,
+ }));
+ }
+ }}
+ />
+ <Location name="locationId" label="Location" />
+
+ <DatePicker
+ name="dueDateOfFirstJob"
+ label="Due Date of First Job"
+ isDisabled={isCustomer}
+ />
+
+ <DatePicker
+ name="dueDateOfLastJob"
+ label="Due Date of Last Job"
+ isDisabled={isCustomer}
+ />
+
+ <Select
+ name="deadlineType"
+ label="Deadline Type"
+ options={deadlineTypes.map((d) => ({
+ value: d,
+ label: (
+ <div className="flex gap-1 items-center">
+ {getDeadlineIcon(d, false)}
+ <span>{getDeadlineText(d)}</span>
+ </div>
+ ),
+ }))}
+ />
+
+ <Customer
+ name="customerId"
+ label="Customer"
+ isOptional
+ />
+
+ <CustomFormFields table="job" />
</div>
- ),
- }))}
- />
-
- {isEditing && (
- <Customer name="customerId" label="Customer" isOptional />
- )}
-
- <CustomFormFields table="job" />
- </div>
- </VStack>
- </CardContent>
- <CardFooter>
- {!isEditing && requiresConfiguration && (
- <Button
- type="button"
- variant={isConfigured ? "secondary" : "primary"}
- onClick={() => {
- configurationDisclosure.onOpen();
- }}
- >
- Configure
- </Button>
- )}
- <Submit
- isDisabled={
- (requiresConfiguration && !isConfigured) ||
- isDisabled ||
- (isEditing
- ? !permissions.can("update", "production")
- : !permissions.can("create", "production"))
- }
- >
- Save
- </Submit>
- </CardFooter>
- </ValidatedForm>
- </Card>
+ </VStack>
+ </CardContent>
+ <CardFooter>
+ {!isEditing && requiresConfiguration && (
+ <Button
+ type="button"
+ variant={isConfigured ? "secondary" : "primary"}
+ onClick={() => {
+ configurationDisclosure.onOpen();
+ }}
+ >
+ Configure
+ </Button>
+ )}
+ <Submit
+ isDisabled={
+ (requiresConfiguration && !isConfigured) ||
+ isDisabled ||
+ !permissions.can("create", "production")
+ }
+ withBlocker={false}
+ >
+ Save
+ </Submit>
+ </CardFooter>
+ </ValidatedForm>
+ </Card>
+ </TabsContent>
+ )}
+ </VStack>
+ </Tabs>
{requiresConfiguration &&
configurationDisclosure.isOpen &&
diff --git a/apps/erp/app/routes/x+/job+/bulk.new.tsx b/apps/erp/app/routes/x+/job+/bulk.new.tsx
new file mode 100644
index 0000000000..dc6422a3e7
--- /dev/null
+++ b/apps/erp/app/routes/x+/job+/bulk.new.tsx
@@ -0,0 +1,154 @@
+import {
+ assertIsPost,
+ error,
+ getCarbonServiceRole,
+ success,
+} from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { validator } from "@carbon/form";
+import { parseDateTime, toCalendarDateTime } from "@internationalized/date";
+import { tasks } from "@trigger.dev/sdk/v3";
+import { redirect, type ActionFunctionArgs } from "@vercel/remix";
+import {
+ bulkJobValidator,
+ upsertJob,
+ upsertJobMethod,
+} from "~/modules/production";
+import { getNextSequence } from "~/modules/settings/settings.service";
+import { setCustomFields } from "~/utils/form";
+import { path } from "~/utils/path";
+
+export const config = { runtime: "nodejs" };
+
+export async function action({ request }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { companyId, userId } = await requirePermissions(request, {
+ create: "production",
+ bypassRls: true,
+ });
+
+ const serviceRole = await getCarbonServiceRole();
+
+ const formData = await request.formData();
+ const validation = await validator(bulkJobValidator).validate(formData);
+ let jobIds: string[] = [];
+
+ if (!validation.data) {
+ throw redirect(
+ path.to.jobs,
+ await flash(request, error(validation.error, "Invalid form data"))
+ );
+ }
+
+ const {
+ dueDateOfFirstJob,
+ dueDateOfLastJob,
+ scrapQuantityPerJob,
+ totalQuantity,
+ quantityPerJob,
+ ...jobData
+ } = validation.data;
+ const jobs = Math.ceil(totalQuantity / quantityPerJob);
+ const quantityOfLastJob = totalQuantity - (jobs - 1) * quantityPerJob;
+
+ let configuration = undefined;
+ if (jobData.configuration) {
+ try {
+ configuration = JSON.parse(jobData.configuration);
+ } catch (error) {
+ console.error(error);
+ }
+ }
+
+ // Calculate due date distribution if both dates are provided
+ let dueDateDistribution: string[] = [];
+ if (dueDateOfFirstJob && dueDateOfLastJob) {
+ const startDate = toCalendarDateTime(parseDateTime(dueDateOfFirstJob));
+ const endDate = toCalendarDateTime(parseDateTime(dueDateOfLastJob));
+ const daysBetween = endDate.compare(startDate);
+ const daysPerJob = Math.floor(daysBetween / (jobs - 1));
+
+ dueDateDistribution = Array.from({ length: jobs }, (_, i) => {
+ if (i === jobs - 1) return dueDateOfLastJob;
+ const jobDate = startDate.add({ days: i * daysPerJob });
+ return jobDate.toString();
+ });
+ }
+
+ for await (const [i] of Array.from({ length: jobs }, (_, i) => [i])) {
+ const nextSequence = await getNextSequence(serviceRole, "job", companyId);
+ if (nextSequence.error) {
+ throw redirect(
+ path.to.newJob,
+ await flash(
+ request,
+ error(nextSequence.error, "Failed to get next sequence")
+ )
+ );
+ }
+ let jobId = nextSequence.data;
+
+ const createJob = await upsertJob(serviceRole, {
+ jobId,
+ ...jobData,
+ quantity: i === jobs - 1 ? quantityOfLastJob : quantityPerJob,
+ scrapQuantity:
+ i === jobs - 1
+ ? Math.ceil(
+ quantityOfLastJob * (scrapQuantityPerJob / quantityPerJob)
+ )
+ : scrapQuantityPerJob,
+ dueDate: dueDateDistribution[i] || dueDateOfFirstJob,
+ configuration,
+ companyId,
+ createdBy: userId,
+ customFields: setCustomFields(formData),
+ });
+
+ if (createJob.error) {
+ throw redirect(
+ path.to.newJob,
+ await flash(request, error(createJob.error, "Failed to insert job"))
+ );
+ }
+
+ const id = createJob.data?.id!;
+ if (createJob.error || !jobId) {
+ throw redirect(
+ path.to.jobs,
+ await flash(request, error(createJob.error, "Failed to insert job"))
+ );
+ }
+
+ const upsertMethod = await upsertJobMethod(serviceRole, "itemToJob", {
+ sourceId: jobData.itemId,
+ targetId: id,
+ companyId,
+ userId,
+ configuration,
+ });
+
+ if (upsertMethod.error) {
+ console.error("Failed to upsert job method", upsertMethod.error);
+ }
+ jobIds.push(id);
+ }
+
+ await tasks.batchTrigger(
+ "recalculate",
+ jobIds.map((id) => ({
+ payload: {
+ type: "jobRequirements",
+ id,
+ companyId,
+ userId,
+ },
+ }))
+ );
+
+ throw redirect(
+ path.to.jobs,
+ await flash(request, success(`Successfully created ${jobs} jobs`))
+ );
+}
diff --git a/apps/erp/app/routes/x+/job+/new.tsx b/apps/erp/app/routes/x+/job+/new.tsx
index 2d2fcd2336..41a5aa7fc0 100644
--- a/apps/erp/app/routes/x+/job+/new.tsx
+++ b/apps/erp/app/routes/x+/job+/new.tsx
@@ -125,7 +125,7 @@ export default function JobNewRoute() {
itemType: "Item" as MethodItemType,
jobId: undefined,
locationId: defaults?.locationId ?? "",
- quantity: 0,
+ quantity: 1,
scrapQuantity: 0,
status: "Draft" as const,
unitOfMeasureCode: "EA",
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index e927c71d35..9db5fccf85 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -721,6 +721,7 @@ export const path = {
newAttributeForCategory: (id: string) =>
generatePath(`${x}/people/attributes/list/${id}/new`),
newBatch: `${x}/inventory/batches/new`,
+ newBulkJob: `${x}/job/bulk/new`,
newChartOfAccount: `${x}/accounting/charts/new`,
newCompany: `${x}/settings/company/new`,
newConsumable: `${x}/consumable/new`,
diff --git a/packages/database/supabase/functions/lib/database.ts b/packages/database/supabase/functions/lib/database.ts
index a731c33bf0..a15dd58f6e 100644
--- a/packages/database/supabase/functions/lib/database.ts
+++ b/packages/database/supabase/functions/lib/database.ts
@@ -19,7 +19,10 @@ export type DB = {
export function getConnectionPool(connections: number) {
const url = Deno.env.get("SUPABASE_DB_URL")!;
- const connectionPoolerUrl = url.replace("5432", "6543");
+
+ const connectionPoolerUrl = url.includes("supabase.co")
+ ? url.replace("5432", "6543")
+ : url;
return new Pool(connectionPoolerUrl, connections);
}