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: add notes to operations with chat-like interface

Brad Barbin3f3df5c9d129
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index 81d7a9c42d..afc1b2a194 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -478,7 +478,7 @@ export async function getProductionDataByOperations(
client: SupabaseClient<Database>,
jobOperationIds: string[]
) {
- const [quantities, events] = await Promise.all([
+ const [quantities, events, notes] = await Promise.all([
client
.from("productionQuantity")
.select(
@@ -491,11 +491,16 @@ export async function getProductionDataByOperations(
"*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableId)))"
)
.in("jobOperationId", jobOperationIds),
+ client
+ .from("jobOperationNote")
+ .select("*")
+ .in("jobOperationId", jobOperationIds),
]);
return {
quantities: quantities.data ?? [],
events: events.data ?? [],
+ notes: notes.data ?? [],
};
}
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
index f3518cdaea..3d4474cd47 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
@@ -7,6 +7,7 @@ import {
Alert,
AlertDescription,
AlertTitle,
+ Avatar,
Badge,
Button,
Card,
@@ -20,11 +21,15 @@ import {
DropdownMenuTrigger,
HStack,
IconButton,
+ Input,
Label,
+ Loading,
+ ScrollArea,
VStack,
cn,
useDebounce,
useDisclosure,
+ useMount,
} from "@carbon/react";
import { Editor, generateHTML } from "@carbon/react/Editor";
import {
@@ -39,17 +44,19 @@ import { AnimatePresence, LayoutGroup, motion } from "framer-motion";
import { nanoid } from "nanoid";
import type { Dispatch, SetStateAction } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
+import { flushSync } from "react-dom";
import {
LuChevronDown,
LuCirclePlus,
LuDollarSign,
LuEllipsisVertical,
LuHammer,
+ LuSend,
LuSettings2,
LuTriangleAlert,
LuX,
} from "react-icons/lu";
-import type { z } from "zod";
+import { type z } from "zod";
import { DirectionAwareTabs, EmployeeAvatar, TimeTypeIcon } from "~/components";
import Activity from "~/components/Activity";
import {
@@ -82,7 +89,7 @@ import {
} from "~/modules/shared";
import type { action as editJobOperationToolAction } from "~/routes/x+/job+/methods+/operation.tool.$id";
import type { action as newJobOperationToolAction } from "~/routes/x+/job+/methods+/operation.tool.new";
-import { useTools } from "~/stores";
+import { usePeople, useTools } from "~/stores";
import { getPrivateUrl, path } from "~/utils/path";
import { jobOperationValidator } from "../../production.models";
import { getProductionEventsPage } from "../../production.service";
@@ -662,6 +669,11 @@ const JobBillOfProcess = ({
</div>
),
},
+ {
+ id: 4,
+ label: "Notes",
+ content: <Notes jobOperationId={item.id} />,
+ },
];
return (
@@ -1773,3 +1785,195 @@ function ToolsForm({
</div>
);
}
+
+type Note = {
+ id: string;
+ createdBy: string;
+ createdAt: string;
+ note: string;
+};
+
+function Notes({ jobOperationId }: { jobOperationId: string }) {
+ const user = useUser();
+ const [employees] = usePeople();
+ const [notes, setNotes] = useState<Note[]>([]);
+ const [isLoading, setIsLoading] = useState(false);
+ const { carbon, accessToken } = useCarbon();
+
+ const fetchNotes = async () => {
+ if (!carbon) return;
+ flushSync(() => {
+ setIsLoading(true);
+ });
+
+ const { data, error } = await carbon
+ ?.from("jobOperationNote")
+ .select("*")
+ .eq("jobOperationId", jobOperationId)
+ .order("createdAt", { ascending: true });
+
+ if (error) {
+ console.error(error);
+ return;
+ }
+ setNotes(data);
+ setIsLoading(false);
+ };
+
+ useMount(() => {
+ fetchNotes();
+ });
+
+ const channelRef = useRef<RealtimeChannel | null>(null);
+
+ useMount(() => {
+ if (!channelRef.current && carbon && accessToken) {
+ carbon.realtime.setAuth(accessToken);
+ channelRef.current = carbon
+ .channel(`job-operation-notes-${jobOperationId}`)
+ .on(
+ "postgres_changes",
+ {
+ event: "INSERT",
+ schema: "public",
+ table: "jobOperationNote",
+ filter: `jobOperationId=eq.${jobOperationId}`,
+ },
+ (payload) => {
+ setNotes((prev) => {
+ if (prev.some((note) => note.id === payload.new.id)) {
+ return prev;
+ }
+ return [...prev, payload.new as Note];
+ });
+ }
+ )
+ .subscribe();
+ }
+
+ return () => {
+ if (channelRef.current) {
+ channelRef.current.unsubscribe();
+ carbon?.removeChannel(channelRef.current);
+ channelRef.current = null;
+ }
+ };
+ });
+
+ useEffect(() => {
+ if (carbon && accessToken && channelRef.current)
+ carbon.realtime.setAuth(accessToken);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [accessToken]);
+
+ const messagesEndRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ messagesEndRef.current?.scrollIntoView({
+ block: "nearest",
+ inline: "start",
+ behavior: notes.length > 0 ? "smooth" : "auto",
+ });
+ }, [notes]);
+
+ const [note, setNote] = useState("");
+
+ const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
+ e.preventDefault();
+
+ if (!note.trim()) return;
+
+ const newNote = {
+ id: nanoid(),
+ jobOperationId,
+ createdBy: user.id,
+ note,
+ createdAt: new Date().toISOString(),
+ companyId: user.company.id,
+ };
+
+ flushSync(() => {
+ setNotes((prev) => [...prev, newNote]);
+ setNote("");
+ });
+
+ await carbon?.from("jobOperationNote").insert(newNote);
+ };
+
+ return (
+ <div className="flex flex-col h-[50dvh]">
+ <ScrollArea className="flex-1 p-4">
+ <Loading isLoading={isLoading}>
+ <div className="flex flex-col gap-3">
+ {notes.map((note) => {
+ const createdBy = employees.find(
+ (employee) => employee.id === note.createdBy
+ );
+ const isUser = note.createdBy === user.id;
+ return (
+ <div
+ key={note.id}
+ className={cn(
+ "flex gap-2 items-end",
+ isUser && "flex-row-reverse"
+ )}
+ >
+ <Avatar
+ src={createdBy?.avatarUrl ?? undefined}
+ name={createdBy?.name}
+ />
+
+ <div className="flex flex-col gap-1 max-w-[80%] ">
+ <div className="flex flex-col gap-1">
+ {!isUser && (
+ <span className="text-xs opacity-70">
+ {createdBy?.name}
+ </span>
+ )}
+ <div
+ className={cn(
+ "rounded-2xl p-3 w-full flex flex-col gap-1",
+ isUser ? "bg-blue-500 text-white" : "bg-muted"
+ )}
+ >
+ <p className="text-sm">{note.note}</p>
+
+ <span className="text-xs opacity-70">
+ {new Date(note.createdAt).toLocaleTimeString([], {
+ hour: "2-digit",
+ minute: "2-digit",
+ })}
+ </span>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+ })}
+ <div ref={messagesEndRef} style={{ height: 0 }} />
+ </div>
+ </Loading>
+ </ScrollArea>
+
+ <div className="border-t p-4">
+ <form className="flex gap-2" onSubmit={handleSubmit}>
+ <Input
+ className="flex-1"
+ placeholder="Type a message..."
+ name="message"
+ value={note}
+ onChange={(e) => setNote(e.target.value)}
+ />
+ <Button
+ className="h-10"
+ aria-label="Send"
+ type="submit"
+ leftIcon={<LuSend />}
+ >
+ Send
+ </Button>
+ </form>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx b/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx
index 761837a825..7ea34949fa 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobEstimatesVsActuals.tsx
@@ -1,3 +1,4 @@
+import type { Database } from "@carbon/database";
import {
Card,
CardAction,
@@ -47,9 +48,9 @@ import {
toZoned,
} from "@internationalized/date";
import { useEffect, useState } from "react";
-import { LuExternalLink, LuNotebook } from "react-icons/lu";
+import { LuCircleChevronRight, LuNotebook } from "react-icons/lu";
import { EmployeeAvatar, EmployeeAvatarGroup } from "~/components";
-import { useCurrencyFormatter, usePercentFormatter } from "~/hooks";
+import { useCurrencyFormatter, usePercentFormatter, useUser } from "~/hooks";
import { makeDurations } from "~/utils/duration";
import { path } from "~/utils/path";
import type { jobOperationValidator } from "../../production.models";
@@ -84,14 +85,17 @@ const JobEstimatesVsActuals = ({
materials,
productionEvents,
productionQuantities,
+ notes,
}: {
operations: Operation[];
materials: Material[];
productionEvents: ProductionEvent[];
productionQuantities: ProductionQuantity[];
+ notes: Database["public"]["Tables"]["jobOperationNote"]["Row"][];
}) => {
const { carbon } = useCarbon();
const { jobId } = useParams();
+ const user = useUser();
if (!jobId) throw new Error("Could not find jobId");
const currencyFormatter = useCurrencyFormatter();
@@ -206,6 +210,10 @@ const JobEstimatesVsActuals = ({
return Array.from(employeeIds);
};
+ const getJobOperationNotes = (operation: Operation) => {
+ return notes.filter((n) => n.jobOperationId === operation.id);
+ };
+
const getNotes = (
operation: Operation,
type?: "Setup" | "Labor" | "Machine"
@@ -285,7 +293,7 @@ const JobEstimatesVsActuals = ({
{operations.map((operation) => {
const estimated = getEstimatedTime(operation);
const actual = getActualTime(operation);
- const notes = getNotes(operation);
+ const notes = getJobOperationNotes(operation);
const isOutside = operation.operationType === "Outside";
if (isOutside) return null;
@@ -361,13 +369,20 @@ const JobEstimatesVsActuals = ({
>
<div className="flex-shrink-0">
<EmployeeAvatar
- employeeId={note.employeeId}
+ employeeId={note.createdBy}
size="sm"
withName={false}
/>
</div>
- <div className="flex-1 rounded-lg bg-muted p-2 text-sm">
- {note.notes}
+ <div
+ className={cn(
+ "flex-1 rounded-lg p-2 text-sm",
+ note.createdBy === user.id
+ ? "bg-blue-500 text-white"
+ : "bg-muted"
+ )}
+ >
+ {note.note}
</div>
</div>
))}
@@ -382,7 +397,7 @@ const JobEstimatesVsActuals = ({
>
<IconButton
variant="ghost"
- icon={<LuExternalLink />}
+ icon={<LuCircleChevronRight />}
aria-label="View Production Events"
/>
</Link>
@@ -487,7 +502,7 @@ const JobEstimatesVsActuals = ({
>
<IconButton
variant="ghost"
- icon={<LuExternalLink />}
+ icon={<LuCircleChevronRight />}
aria-label="View Production Events"
/>
</Link>
diff --git a/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx b/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx
index 54d80db0eb..16b4f50ae3 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx
@@ -160,6 +160,7 @@ export default function JobMakeMethodRoute() {
operations={operations}
productionEvents={resolvedProductionData.events}
productionQuantities={resolvedProductionData.quantities}
+ notes={resolvedProductionData.notes}
/>
)}
</Await>
diff --git a/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx b/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx
index 4a5cb0b479..d828dd2583 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx
@@ -130,6 +130,7 @@ export default function JobMakeMethodRoute() {
operations={operations}
productionEvents={resolvedProductionData.events}
productionQuantities={resolvedProductionData.quantities}
+ notes={resolvedProductionData.notes}
/>
)}
</Await>
diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsx
index 829ee06ddd..c4ecd72838 100644
--- a/apps/mes/app/components/JobOperation.tsx
+++ b/apps/mes/app/components/JobOperation.tsx
@@ -15,6 +15,7 @@ import {
HStack,
IconButton,
Input,
+ Loading,
Modal,
ModalBody,
ModalContent,
@@ -121,6 +122,7 @@ import type {
PostgrestSingleResponse,
RealtimeChannel,
} from "@supabase/supabase-js";
+import { nanoid } from "nanoid";
import { flushSync } from "react-dom";
import { FaTasks } from "react-icons/fa";
import { FaCheck, FaPause, FaPlay, FaPlus, FaTrash } from "react-icons/fa6";
@@ -143,42 +145,6 @@ import { useItems, usePeople } from "~/stores";
import ItemThumbnail from "./ItemThumbnail";
import ScrapReason from "./ScrapReason";
-const MOCK_NOTES = [
- {
- id: "c8j2m4k9n1",
- jobOperationId: "op123",
- note: "Setup completed successfully. All tooling verified.",
- companyId: "comp789",
- createdAt: "2024-01-15T14:30:00Z",
- createdBy: "user456",
- updatedBy: null,
- updatedAt: null,
- productionQuantityId: "pq123",
- },
- {
- id: "d9k3n5m2p4",
- jobOperationId: "op123",
- note: "Quality check performed - dimensions within spec",
- companyId: "comp789",
- createdAt: "2024-01-15T16:45:00Z",
- createdBy: "16c54d5a-fc00-4c54-ac34-25e43f85e366",
- updatedBy: "user456",
- updatedAt: "2024-01-15T17:00:00Z",
- productionQuantityId: "pq124",
- },
- {
- id: "e1m4n7p3q5",
- jobOperationId: "op123",
- note: "Machine maintenance required - coolant levels low",
- companyId: "comp789",
- createdAt: "2024-01-16T09:15:00Z",
- createdBy: "user123",
- updatedBy: null,
- updatedAt: null,
- productionQuantityId: null,
- },
-];
-
type JobOperationProps = {
events: ProductionEvent[];
files: Promise<StorageItem[]>;
@@ -199,8 +165,6 @@ export const JobOperation = ({
workCenter,
}: JobOperationProps) => {
const navigate = useNavigate();
- const user = useUser();
- const [employees] = usePeople();
const { downloadFile, downloadModel, getFilePath } = useFiles(job);
@@ -733,63 +697,7 @@ export const JobOperation = ({
</ScrollArea>
</TabsContent>
<TabsContent value="notes">
- <div className="flex flex-col h-[calc(100dvh-var(--header-height)*2-var(--controls-height)-2rem)]">
- <ScrollArea className="flex-1 p-4">
- <div className="flex flex-col-reverse gap-3">
- {MOCK_NOTES.map((note) => {
- const createdBy = employees.find(
- (employee) => employee.id === note.createdBy
- );
- return (
- <div
- key={note.id}
- className={cn(
- "flex gap-2",
- note.createdBy === user.id && "flex-row-reverse"
- )}
- >
- <Avatar name={createdBy?.name} />
-
- <div
- className={cn(
- "max-w-[80%] rounded-2xl p-3",
- note.createdBy === user.id
- ? "bg-blue-500 text-blue-white"
- : "bg-muted"
- )}
- >
- <p className="text-sm">{note.note}</p>
- <span className="text-xs opacity-70">
- {new Date(note.createdAt).toLocaleTimeString([], {
- hour: "2-digit",
- minute: "2-digit",
- })}
- </span>
- </div>
- </div>
- );
- })}
- </div>
- </ScrollArea>
-
- <div className="border-t p-4">
- <form className="flex gap-2">
- <Input
- className="flex-1"
- placeholder="Type a message..."
- name="message"
- />
- <Button
- className="h-10"
- aria-label="Send"
- type="submit"
- leftIcon={<LuSend />}
- >
- Send
- </Button>
- </form>
- </div>
- </div>
+ <Notes operation={operation} />
</TabsContent>
{!["instructions", "notes"].includes(activeTab) && (
<Controls>
@@ -1081,6 +989,197 @@ export const JobOperation = ({
);
};
+type Note = {
+ id: string;
+ createdBy: string;
+ createdAt: string;
+ note: string;
+};
+
+function Notes({ operation }: { operation: OperationWithDetails }) {
+ const user = useUser();
+ const [employees] = usePeople();
+ const [notes, setNotes] = useState<Note[]>([]);
+ const [isLoading, setIsLoading] = useState(false);
+ const { carbon, accessToken } = useCarbon();
+
+ const fetchNotes = async () => {
+ if (!carbon) return;
+ flushSync(() => {
+ setIsLoading(true);
+ });
+
+ const { data, error } = await carbon
+ ?.from("jobOperationNote")
+ .select("*")
+ .eq("jobOperationId", operation.id)
+ .order("createdAt", { ascending: true });
+
+ if (error) {
+ console.error(error);
+ return;
+ }
+ setNotes(data);
+ setIsLoading(false);
+ };
+
+ useMount(() => {
+ fetchNotes();
+ });
+
+ const channelRef = useRef<RealtimeChannel | null>(null);
+
+ useMount(() => {
+ if (!channelRef.current && carbon && accessToken) {
+ carbon.realtime.setAuth(accessToken);
+ channelRef.current = carbon
+ .channel(`job-operation-notes-${operation.id}`)
+ .on(
+ "postgres_changes",
+ {
+ event: "INSERT",
+ schema: "public",
+ table: "jobOperationNote",
+ filter: `jobOperationId=eq.${operation.id}`,
+ },
+ (payload) => {
+ setNotes((prev) => {
+ if (prev.some((note) => note.id === payload.new.id)) {
+ return prev;
+ }
+ return [...prev, payload.new as Note];
+ });
+ }
+ )
+ .subscribe();
+ }
+
+ return () => {
+ if (channelRef.current) {
+ channelRef.current.unsubscribe();
+ carbon?.removeChannel(channelRef.current);
+ channelRef.current = null;
+ }
+ };
+ });
+
+ useEffect(() => {
+ if (carbon && accessToken && channelRef.current)
+ carbon.realtime.setAuth(accessToken);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [accessToken]);
+
+ const messagesEndRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ messagesEndRef.current?.scrollIntoView({
+ block: "start",
+ behavior: notes.length > 0 ? "smooth" : "auto",
+ });
+ }, [notes]);
+
+ const [note, setNote] = useState("");
+
+ const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
+ e.preventDefault();
+
+ if (!note.trim()) return;
+
+ const newNote = {
+ id: nanoid(),
+ jobOperationId: operation.id,
+ createdBy: user.id,
+ note,
+ createdAt: new Date().toISOString(),
+ companyId: user.company.id,
+ };
+
+ flushSync(() => {
+ setNotes((prev) => [...prev, newNote]);
+ setNote("");
+ });
+
+ await carbon?.from("jobOperationNote").insert(newNote);
+ };
+
+ return (
+ <div className="flex flex-col h-[calc(100dvh-var(--header-height)*2)]">
+ <ScrollArea className="flex-1 p-4">
+ <Loading isLoading={isLoading}>
+ <div className="flex flex-col gap-3">
+ {notes.map((note) => {
+ const createdBy = employees.find(
+ (employee) => employee.id === note.createdBy
+ );
+ const isUser = note.createdBy === user.id;
+ return (
+ <div
+ key={note.id}
+ className={cn(
+ "flex gap-2 items-end",
+ isUser && "flex-row-reverse"
+ )}
+ >
+ <Avatar
+ src={createdBy?.avatarUrl ?? undefined}
+ name={createdBy?.name}
+ />
+
+ <div className="flex flex-col gap-1 max-w-[80%] ">
+ <div className="flex flex-col gap-1">
+ {!isUser && (
+ <span className="text-xs opacity-70">
+ {createdBy?.name}
+ </span>
+ )}
+ <div
+ className={cn(
+ "rounded-2xl p-3 w-full flex flex-col gap-1",
+ isUser ? "bg-blue-500 text-white" : "bg-muted"
+ )}
+ >
+ <p className="text-sm">{note.note}</p>
+
+ <span className="text-xs opacity-70">
+ {new Date(note.createdAt).toLocaleTimeString([], {
+ hour: "2-digit",
+ minute: "2-digit",
+ })}
+ </span>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+ })}
+ <div ref={messagesEndRef} style={{ height: 0 }} />
+ </div>
+ </Loading>
+ </ScrollArea>
+
+ <div className="border-t p-4">
+ <form className="flex gap-2" onSubmit={handleSubmit}>
+ <Input
+ className="flex-1"
+ placeholder="Type a message..."
+ name="message"
+ value={note}
+ onChange={(e) => setNote(e.target.value)}
+ />
+ <Button
+ className="h-10"
+ aria-label="Send"
+ type="submit"
+ leftIcon={<LuSend />}
+ >
+ Send
+ </Button>
+ </form>
+ </div>
+ </div>
+ );
+}
+
function useOperation(
operation: OperationWithDetails,
events: ProductionEvent[]
@@ -1851,7 +1950,6 @@ function QuantityModal({
}
isReadOnly
/>
- <TextArea label="Notes" name="notes" />
</>
)}
</VStack>
diff --git a/apps/mes/package.json b/apps/mes/package.json
index b96589972f..929fb5bc69 100644
--- a/apps/mes/package.json
+++ b/apps/mes/package.json
@@ -30,6 +30,7 @@
"cookie": "0.6.0",
"framer-motion": "^11.1.7",
"isbot": "3.6.13",
+ "nanoid": "^5.0.4",
"non.geist": "~1.0.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
diff --git a/package-lock.json b/package-lock.json
index 08c32fae33..de53d8e9ff 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -180,6 +180,7 @@
"cookie": "0.6.0",
"framer-motion": "^11.1.7",
"isbot": "3.6.13",
+ "nanoid": "^5.0.4",
"non.geist": "~1.0.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index a894a7d37a..2d13728855 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -8727,6 +8727,7 @@ export type Database = {
id: string
jobOperationId: string
note: string
+ productionQuantityId: string | null
updatedAt: string | null
updatedBy: string | null
}
@@ -8737,6 +8738,7 @@ export type Database = {
id?: string
jobOperationId: string
note: string
+ productionQuantityId?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -8747,6 +8749,7 @@ export type Database = {
id?: string
jobOperationId?: string
note?: string
+ productionQuantityId?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -8814,6 +8817,13 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
+ {
+ foreignKeyName: "jobOperationNote_productionQuantityId_fkey"
+ columns: ["productionQuantityId"]
+ isOneToOne: false
+ referencedRelation: "productionQuantity"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "jobOperationNote_updatedBy_fkey"
columns: ["updatedBy"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index a894a7d37a..2d13728855 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -8727,6 +8727,7 @@ export type Database = {
id: string
jobOperationId: string
note: string
+ productionQuantityId: string | null
updatedAt: string | null
updatedBy: string | null
}
@@ -8737,6 +8738,7 @@ export type Database = {
id?: string
jobOperationId: string
note: string
+ productionQuantityId?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -8747,6 +8749,7 @@ export type Database = {
id?: string
jobOperationId?: string
note?: string
+ productionQuantityId?: string | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -8814,6 +8817,13 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
+ {
+ foreignKeyName: "jobOperationNote_productionQuantityId_fkey"
+ columns: ["productionQuantityId"]
+ isOneToOne: false
+ referencedRelation: "productionQuantity"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "jobOperationNote_updatedBy_fkey"
columns: ["updatedBy"]
diff --git a/packages/database/supabase/migrations/20250113145319_operation-notes.sql b/packages/database/supabase/migrations/20250113145319_operation-notes.sql
index 3d2647abfd..97198bb689 100644
--- a/packages/database/supabase/migrations/20250113145319_operation-notes.sql
+++ b/packages/database/supabase/migrations/20250113145319_operation-notes.sql
@@ -49,3 +49,5 @@ ALTER TABLE "jobOperationNote" ADD COLUMN "productionQuantityId" TEXT;
ALTER TABLE "jobOperationNote" ADD CONSTRAINT "jobOperationNote_productionQuantityId_fkey" FOREIGN KEY ("productionQuantityId") REFERENCES "productionQuantity"("id") ON UPDATE CASCADE ON DELETE CASCADE;
CREATE INDEX "jobOperationNote_productionQuantityId_fkey" ON "jobOperationNote"("productionQuantityId");
+
+ALTER PUBLICATION supabase_realtime ADD TABLE "jobOperationNote";