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 methods for attribute crud on bops

Brad Barbinee02d8f788c7
diff --git a/apps/erp/app/components/Icons.tsx b/apps/erp/app/components/Icons.tsx
index d73f42a76e..b38f5f2ab4 100644
--- a/apps/erp/app/components/Icons.tsx
+++ b/apps/erp/app/components/Icons.tsx
@@ -5,7 +5,6 @@ import { FaCodePullRequest } from "react-icons/fa6";
import {
LuAtom,
LuBarcode,
- LuBeaker,
LuBox,
LuCircle,
LuCircleCheck,
@@ -20,12 +19,13 @@ import {
LuHeadphones,
LuList,
LuPizza,
+ LuQrCode,
+ LuRuler,
LuShoppingCart,
LuSquare,
LuSwords,
LuTimer,
LuToggleLeft,
- LuType,
LuUser,
} from "react-icons/lu";
@@ -186,9 +186,9 @@ export const ProcedureAttributeTypeIcon = ({
}) => {
switch (type) {
case "Value":
- return <LuType className={cn("text-emerald-600", className)} />;
+ return <LuQrCode className={cn("text-emerald-600", className)} />;
case "Measurement":
- return <LuBeaker className={cn("text-blue-600", className)} />;
+ return <LuRuler className={cn("text-blue-600", className)} />;
case "Checkbox":
return <LuToggleLeft className={cn("text-purple-600", className)} />;
case "Timestamp":
diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.ts
index 7959630aba..674d53b1e0 100644
--- a/apps/erp/app/modules/items/items.service.ts
+++ b/apps/erp/app/modules/items/items.service.ts
@@ -7,6 +7,7 @@ import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
import { sanitize } from "~/utils/supabase";
import type {
+ operationAttributeValidator,
operationParameterValidator,
operationToolValidator,
} from "../shared";
@@ -158,6 +159,13 @@ export async function deleteMethodMaterial(
return client.from("methodMaterial").delete().eq("id", id);
}
+export async function deleteMethodOperationAttribute(
+ client: SupabaseClient<Database>,
+ id: string
+) {
+ return client.from("methodOperationAttribute").delete().eq("id", id);
+}
+
export async function deleteMethodOperationParameter(
client: SupabaseClient<Database>,
id: string
@@ -872,7 +880,9 @@ export async function getMethodOperationsByMakeMethodId(
) {
return client
.from("methodOperation")
- .select("*, methodOperationTool(*), methodOperationParameter(*)")
+ .select(
+ "*, methodOperationTool(*), methodOperationParameter(*), methodOperationAttribute(*)"
+ )
.eq("makeMethodId", makeMethodId)
.order("order", { ascending: true });
}
@@ -1894,6 +1904,35 @@ export async function upsertMethodOperation(
.single();
}
+export async function upsertMethodOperationAttribute(
+ client: SupabaseClient<Database>,
+ methodOperationAttribute:
+ | (Omit<z.infer<typeof operationAttributeValidator>, "id"> & {
+ companyId: string;
+ createdBy: string;
+ })
+ | (Omit<z.infer<typeof operationParameterValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ updatedAt: string;
+ })
+) {
+ if ("createdBy" in methodOperationAttribute) {
+ return client
+ .from("methodOperationAttribute")
+ .insert(methodOperationAttribute)
+ .select("id")
+ .single();
+ }
+
+ return client
+ .from("methodOperationAttribute")
+ .update(sanitize(methodOperationAttribute))
+ .eq("id", methodOperationAttribute.id)
+ .select("id")
+ .single();
+}
+
export async function upsertMethodOperationParameter(
client: SupabaseClient<Database>,
methodOperationParameter:
diff --git a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
index 27ed4c1c9a..e422d77a34 100644
--- a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -76,7 +76,11 @@ import { SortableList, SortableListItem } from "~/components/SortableList";
import { usePermissions, useUser } from "~/hooks";
import { useTags } from "~/hooks/useTags";
-import type { OperationParameter, OperationTool } from "~/modules/shared";
+import type {
+ OperationAttribute,
+ OperationParameter,
+ OperationTool,
+} from "~/modules/shared";
import {
methodOperationOrders,
operationParameterValidator,
@@ -110,6 +114,7 @@ type BillOfProcessProps = {
operations: (Operation & {
methodOperationTool: OperationTool[];
methodOperationParameter: OperationParameter[];
+ methodOperationAttribute: OperationAttribute[];
})[];
parameters?: ConfigurationParameter[];
tags: { name: string }[];
@@ -390,6 +395,9 @@ const BillOfProcess = ({
const parameters =
initialOperations.find((o) => o.id === item.id)
?.methodOperationParameter ?? [];
+ const attributes =
+ initialOperations.find((o) => o.id === item.id)
+ ?.methodOperationAttribute ?? [];
const tabs = [
{
@@ -500,6 +508,16 @@ const BillOfProcess = ({
</div>
),
},
+ {
+ id: 4,
+ label: (
+ <span className="flex items-center gap-2">
+ <span>Attributes</span>
+ {attributes.length > 0 && <Count count={attributes.length} />}
+ </span>
+ ),
+ content: <div>Attributes</div>,
+ },
];
return (
diff --git a/apps/erp/app/modules/production/production.models.ts b/apps/erp/app/modules/production/production.models.ts
index 87451db17c..01bef22cfa 100644
--- a/apps/erp/app/modules/production/production.models.ts
+++ b/apps/erp/app/modules/production/production.models.ts
@@ -5,6 +5,7 @@ import {
methodOperationOrders,
methodType,
operationTypes,
+ procedureAttributeType,
standardFactorType,
} from "../shared";
@@ -54,16 +55,6 @@ export const jobOperationStatus = [
export const procedureStatus = ["Draft", "Active", "Archived"] as const;
-export const procedureAttributeType = [
- "Value",
- "Measurement",
- "Checkbox",
- "Timestamp",
- "Person",
- "List",
- "File",
-] as const;
-
const baseJobValidator = z.object({
id: zfd.text(z.string().optional()),
jobId: zfd.text(z.string().optional()),
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index 431b52ef32..5a22a385fb 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -6,6 +6,7 @@ import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
import { sanitize } from "~/utils/supabase";
import type {
+ operationAttributeValidator,
operationParameterValidator,
operationToolValidator,
} from "../shared";
@@ -44,6 +45,13 @@ export async function deleteJobOperation(
return client.from("jobOperation").delete().eq("id", jobOperationId);
}
+export async function deleteJobOperationAttribute(
+ client: SupabaseClient<Database>,
+ id: string
+) {
+ return client.from("jobOperationAttribute").delete().eq("id", id);
+}
+
export async function deleteJobOperationParameter(
client: SupabaseClient<Database>,
id: string
@@ -947,6 +955,35 @@ export async function upsertJobOperation(
.single();
}
+export async function upsertJobOperationAttribute(
+ client: SupabaseClient<Database>,
+ jobOperationAttribute:
+ | (Omit<z.infer<typeof operationAttributeValidator>, "id"> & {
+ companyId: string;
+ createdBy: string;
+ })
+ | (Omit<z.infer<typeof operationAttributeValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ updatedAt: string;
+ })
+) {
+ if ("createdBy" in jobOperationAttribute) {
+ return client
+ .from("jobOperationAttribute")
+ .insert(jobOperationAttribute)
+ .select("id")
+ .single();
+ }
+
+ return client
+ .from("jobOperationAttribute")
+ .update(sanitize(jobOperationAttribute))
+ .eq("id", jobOperationAttribute.id)
+ .select("id")
+ .single();
+}
+
export async function upsertJobOperationParameter(
client: SupabaseClient<Database>,
jobOperationParameter:
diff --git a/apps/erp/app/modules/production/ui/Procedures/ProcedureAttributesExplorer.tsx b/apps/erp/app/modules/production/ui/Procedures/ProcedureAttributesExplorer.tsx
index 57b7d3b3de..cd8c9d2493 100644
--- a/apps/erp/app/modules/production/ui/Procedures/ProcedureAttributesExplorer.tsx
+++ b/apps/erp/app/modules/production/ui/Procedures/ProcedureAttributesExplorer.tsx
@@ -33,6 +33,7 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
useDebounce,
+ cn,
} from "@carbon/react";
import { prettifyKeyboardShortcut } from "@carbon/utils";
import { useFetcher, useParams } from "@remix-run/react";
@@ -50,15 +51,13 @@ import { usePermissions, useRouteData } from "~/hooks";
import { path } from "~/utils/path";
import type { Procedure, ProcedureAttribute } from "../../types";
import { ConfirmDelete } from "~/components/Modals";
-import {
- procedureAttributeType,
- procedureAttributeValidator,
-} from "../../production.models";
+import { procedureAttributeValidator } from "../../production.models";
import { ProcedureAttributeTypeIcon } from "~/components/Icons";
import { UnitOfMeasure } from "~/components/Form";
import type { z } from "zod";
import { Reorder } from "framer-motion";
import { flushSync } from "react-dom";
+import { procedureAttributeType } from "~/modules/shared";
export default function ProcedureAttributesExplorer() {
const { id } = useParams();
@@ -197,7 +196,6 @@ export default function ProcedureAttributesExplorer() {
<Reorder.Item
key={sortId}
value={sortId}
- className="rounded-lg w-full"
dragListener={!isDisabled}
>
<ProcedureAttributeItem
@@ -298,9 +296,10 @@ function ProcedureAttributeItem({
return (
<HStack
- className={`group w-full p-2 items-center hover:bg-accent/30 relative border-b ${
+ className={cn(
+ "group w-full p-2 items-center hover:bg-accent/30 relative border-b bg-card",
!isDisabled ? "cursor-pointer" : ""
- }`}
+ )}
>
<IconButton
aria-label="Drag handle"
diff --git a/apps/erp/app/modules/sales/sales.service.ts b/apps/erp/app/modules/sales/sales.service.ts
index f7015175c3..4d5aabed6c 100644
--- a/apps/erp/app/modules/sales/sales.service.ts
+++ b/apps/erp/app/modules/sales/sales.service.ts
@@ -8,6 +8,7 @@ import { setGenericQueryFilters } from "~/utils/query";
import { sanitize } from "~/utils/supabase";
import { getCurrencyByCode } from "../accounting";
import type {
+ operationAttributeValidator,
operationParameterValidator,
operationToolValidator,
} from "../shared";
@@ -219,6 +220,13 @@ export async function deleteQuoteOperation(
return client.from("quoteOperation").delete().eq("id", quoteOperationId);
}
+export async function deleteQuoteOperationAttribute(
+ client: SupabaseClient<Database>,
+ id: string
+) {
+ return client.from("quoteOperationAttribute").delete().eq("id", id);
+}
+
export async function deleteQuoteOperationParameter(
client: SupabaseClient<Database>,
id: string
@@ -979,7 +987,9 @@ export async function getQuoteOperationsByMethodId(
) {
return client
.from("quoteOperation")
- .select("*, quoteOperationTool(*), quoteOperationParameter(*)")
+ .select(
+ "*, quoteOperationTool(*), quoteOperationParameter(*), quoteOperationAttribute(*)"
+ )
.eq("quoteMakeMethodId", quoteMakeMethodId)
.order("order", { ascending: true });
}
@@ -2176,6 +2186,35 @@ export async function upsertQuoteOperation(
.single();
}
+export async function upsertQuoteOperationAttribute(
+ client: SupabaseClient<Database>,
+ quoteOperationAttribute:
+ | (Omit<z.infer<typeof operationAttributeValidator>, "id"> & {
+ companyId: string;
+ createdBy: string;
+ })
+ | (Omit<z.infer<typeof operationAttributeValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ updatedAt: string;
+ })
+) {
+ if ("createdBy" in quoteOperationAttribute) {
+ return client
+ .from("quoteOperationAttribute")
+ .insert(quoteOperationAttribute)
+ .select("id")
+ .single();
+ }
+
+ return client
+ .from("quoteOperationAttribute")
+ .update(sanitize(quoteOperationAttribute))
+ .eq("id", quoteOperationAttribute.id)
+ .select("id")
+ .single();
+}
+
export async function upsertQuoteOperationParameter(
client: SupabaseClient<Database>,
quoteOperationParameter:
diff --git a/apps/erp/app/modules/shared/shared.models.ts b/apps/erp/app/modules/shared/shared.models.ts
index 312a8c37af..eda0df560d 100644
--- a/apps/erp/app/modules/shared/shared.models.ts
+++ b/apps/erp/app/modules/shared/shared.models.ts
@@ -70,6 +70,16 @@ export const noteValidator = z.object({
export const operationTypes = ["Inside", "Outside"] as const;
+export const procedureAttributeType = [
+ "Value",
+ "Measurement",
+ "Checkbox",
+ "Timestamp",
+ "Person",
+ "List",
+ "File",
+] as const;
+
export const processTypes = [
"Inside",
"Outside",
@@ -82,6 +92,62 @@ export const feedbackValidator = z.object({
location: z.string(),
});
+export const operationAttributeValidator = z
+ .object({
+ id: zfd.text(z.string().optional()),
+ operationId: z.string().min(1, { message: "Operation is required" }),
+ name: z.string().min(1, { message: "Name is required" }),
+ description: zfd.text(z.string().optional()),
+ type: z.enum(procedureAttributeType, {
+ errorMap: () => ({ message: "Type is required" }),
+ }),
+ unitOfMeasureCode: zfd.text(z.string().optional()),
+ minValue: zfd.numeric(z.number().min(0).optional()),
+ maxValue: zfd.numeric(z.number().min(0).optional()),
+ listValues: z.array(z.string()).optional(),
+ sortOrder: zfd.numeric(z.number().min(0).optional()),
+ })
+ .refine(
+ (data) => {
+ if (data.type === "Measurement") {
+ return !!data.unitOfMeasureCode;
+ }
+ return true;
+ },
+ {
+ message: "Unit of measure is required",
+ path: ["unitOfMeasureCode"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (data.type === "List") {
+ return (
+ !!data.listValues &&
+ data.listValues.length > 0 &&
+ data.listValues.every((option) => option.trim() !== "")
+ );
+ }
+ return true;
+ },
+ {
+ message: "List options are required",
+ path: ["listOptions"],
+ }
+ )
+ .refine(
+ (data) => {
+ if (data.minValue != null && data.maxValue != null) {
+ return data.maxValue >= data.minValue;
+ }
+ return true;
+ },
+ {
+ message: "Maximum value must be greater than or equal to minimum value",
+ path: ["maxValue"],
+ }
+ );
+
export const operationToolValidator = z.object({
id: zfd.text(z.string().optional()),
operationId: z.string().min(1, { message: "Operation is required" }),
diff --git a/apps/erp/app/modules/shared/types.ts b/apps/erp/app/modules/shared/types.ts
index 4f92842f5d..04846d3ee4 100644
--- a/apps/erp/app/modules/shared/types.ts
+++ b/apps/erp/app/modules/shared/types.ts
@@ -4,6 +4,7 @@ import type { StorageItem } from "~/types";
import type {
methodItemType,
methodType,
+ operationAttributeValidator,
operationParameterValidator,
operationToolValidator,
standardFactorType,
@@ -47,6 +48,13 @@ export type Note = NonNullable<
Awaited<ReturnType<typeof getNotes>>["data"]
>[number];
+export type OperationAttribute = z.infer<typeof operationAttributeValidator> & {
+ createdBy: string;
+ createdAt: string;
+ updatedBy: string | null;
+ updatedAt: string | null;
+};
+
export type OperationTool = z.infer<typeof operationToolValidator> & {
createdBy: string;
createdAt: string;
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index e10c426adc..0e6931426b 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -9081,6 +9081,151 @@ export type Database = {
},
]
}
+ jobOperationAttribute: {
+ Row: {
+ companyId: string
+ createdAt: string
+ createdBy: string
+ description: string | null
+ fileTypes: string[] | null
+ id: string
+ listValues: string[] | null
+ maxValue: number | null
+ minValue: number | null
+ name: string
+ operationId: string
+ required: boolean | null
+ sortOrder: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode: string | null
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name: string
+ operationId: string
+ required?: boolean | null
+ sortOrder?: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name?: string
+ operationId?: string
+ required?: boolean | null
+ sortOrder?: number
+ type?: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "jobOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_operationId_fkey"
+ columns: ["operationId"]
+ isOneToOne: false
+ referencedRelation: "jobOperation"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_operationId_fkey"
+ columns: ["operationId"]
+ isOneToOne: false
+ referencedRelation: "jobOperationsWithMakeMethods"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
jobOperationNote: {
Row: {
companyId: string
@@ -10908,6 +11053,144 @@ export type Database = {
},
]
}
+ methodOperationAttribute: {
+ Row: {
+ companyId: string
+ createdAt: string
+ createdBy: string
+ description: string | null
+ fileTypes: string[] | null
+ id: string
+ listValues: string[] | null
+ maxValue: number | null
+ minValue: number | null
+ name: string
+ operationId: string
+ required: boolean | null
+ sortOrder: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode: string | null
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name: string
+ operationId: string
+ required?: boolean | null
+ sortOrder?: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name?: string
+ operationId?: string
+ required?: boolean | null
+ sortOrder?: number
+ type?: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "methodOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_operationId_fkey"
+ columns: ["operationId"]
+ isOneToOne: false
+ referencedRelation: "methodOperation"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
methodOperationParameter: {
Row: {
companyId: string
@@ -18129,6 +18412,151 @@ export type Database = {
},
]
}
+ quoteOperationAttribute: {
+ Row: {
+ companyId: string
+ createdAt: string
+ createdBy: string
+ description: string | null
+ fileTypes: string[] | null
+ id: string
+ listValues: string[] | null
+ maxValue: number | null
+ minValue: number | null
+ name: string
+ operationId: string
+ required: boolean | null
+ sortOrder: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode: string | null
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name: string
+ operationId: string
+ required?: boolean | null
+ sortOrder?: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name?: string
+ operationId?: string
+ required?: boolean | null
+ sortOrder?: number
+ type?: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "quoteOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_operationId_fkey"
+ columns: ["operationId"]
+ isOneToOne: false
+ referencedRelation: "quoteOperation"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_operationId_fkey"
+ columns: ["operationId"]
+ isOneToOne: false
+ referencedRelation: "quoteOperationsWithMakeMethods"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
quoteOperationParameter: {
Row: {
companyId: string
@@ -29528,14 +29956,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -32475,14 +32903,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index e10c426adc..0e6931426b 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -9081,6 +9081,151 @@ export type Database = {
},
]
}
+ jobOperationAttribute: {
+ Row: {
+ companyId: string
+ createdAt: string
+ createdBy: string
+ description: string | null
+ fileTypes: string[] | null
+ id: string
+ listValues: string[] | null
+ maxValue: number | null
+ minValue: number | null
+ name: string
+ operationId: string
+ required: boolean | null
+ sortOrder: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode: string | null
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name: string
+ operationId: string
+ required?: boolean | null
+ sortOrder?: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name?: string
+ operationId?: string
+ required?: boolean | null
+ sortOrder?: number
+ type?: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "jobOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_operationId_fkey"
+ columns: ["operationId"]
+ isOneToOne: false
+ referencedRelation: "jobOperation"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_operationId_fkey"
+ columns: ["operationId"]
+ isOneToOne: false
+ referencedRelation: "jobOperationsWithMakeMethods"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "jobOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
jobOperationNote: {
Row: {
companyId: string
@@ -10908,6 +11053,144 @@ export type Database = {
},
]
}
+ methodOperationAttribute: {
+ Row: {
+ companyId: string
+ createdAt: string
+ createdBy: string
+ description: string | null
+ fileTypes: string[] | null
+ id: string
+ listValues: string[] | null
+ maxValue: number | null
+ minValue: number | null
+ name: string
+ operationId: string
+ required: boolean | null
+ sortOrder: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode: string | null
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name: string
+ operationId: string
+ required?: boolean | null
+ sortOrder?: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name?: string
+ operationId?: string
+ required?: boolean | null
+ sortOrder?: number
+ type?: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "methodOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_operationId_fkey"
+ columns: ["operationId"]
+ isOneToOne: false
+ referencedRelation: "methodOperation"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "methodOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
methodOperationParameter: {
Row: {
companyId: string
@@ -18129,6 +18412,151 @@ export type Database = {
},
]
}
+ quoteOperationAttribute: {
+ Row: {
+ companyId: string
+ createdAt: string
+ createdBy: string
+ description: string | null
+ fileTypes: string[] | null
+ id: string
+ listValues: string[] | null
+ maxValue: number | null
+ minValue: number | null
+ name: string
+ operationId: string
+ required: boolean | null
+ sortOrder: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode: string | null
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name: string
+ operationId: string
+ required?: boolean | null
+ sortOrder?: number
+ type: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ description?: string | null
+ fileTypes?: string[] | null
+ id?: string
+ listValues?: string[] | null
+ maxValue?: number | null
+ minValue?: number | null
+ name?: string
+ operationId?: string
+ required?: boolean | null
+ sortOrder?: number
+ type?: Database["public"]["Enums"]["procedureAttributeType"]
+ unitOfMeasureCode?: string | null
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "quoteOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_operationId_fkey"
+ columns: ["operationId"]
+ isOneToOne: false
+ referencedRelation: "quoteOperation"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_operationId_fkey"
+ columns: ["operationId"]
+ isOneToOne: false
+ referencedRelation: "quoteOperationsWithMakeMethods"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteOperationAttribute_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
quoteOperationParameter: {
Row: {
companyId: string
@@ -29528,14 +29956,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -32475,14 +32903,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
diff --git a/packages/database/supabase/migrations/20250216192838_procedures.sql b/packages/database/supabase/migrations/20250216192838_procedures.sql
index 7be4a659c3..14ddc22b4b 100644
--- a/packages/database/supabase/migrations/20250216192838_procedures.sql
+++ b/packages/database/supabase/migrations/20250216192838_procedures.sql
@@ -188,4 +188,217 @@ CREATE OR REPLACE VIEW "procedures" WITH(SECURITY_INVOKER=true) AS
)
GROUP BY p1."id", p1."name", p1."version", p1."status", p1."assignee", p1."companyId", p1."processId";
-
\ No newline at end of file
+
+CREATE TABLE "methodOperationAttribute" (
+ "id" TEXT NOT NULL DEFAULT xid(),
+ "name" TEXT NOT NULL,
+ "description" TEXT,
+ "required" BOOLEAN DEFAULT FALSE,
+ "sortOrder" DOUBLE PRECISION NOT NULL DEFAULT 1,
+ "type" "procedureAttributeType" NOT NULL,
+ "unitOfMeasureCode" TEXT,
+ "minValue" DECIMAL,
+ "maxValue" DECIMAL,
+ "listValues" TEXT[],
+ "fileTypes" TEXT[],
+ "operationId" TEXT NOT NULL,
+ "companyId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
+ "createdBy" TEXT NOT NULL,
+ "updatedAt" TIMESTAMP WITH TIME ZONE,
+ "updatedBy" TEXT,
+
+ CONSTRAINT "methodOperationAttribute_pkey" PRIMARY KEY ("id"),
+ CONSTRAINT "methodOperationAttribute_operationId_fkey" FOREIGN KEY ("operationId") REFERENCES "methodOperation"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT "methodOperationAttribute_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id") ON UPDATE CASCADE,
+ CONSTRAINT "methodOperationAttribute_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE
+);
+
+CREATE INDEX "methodOperationAttribute_companyId_idx" ON "methodOperationAttribute"("companyId");
+CREATE INDEX "methodOperationAttribute_operationId_idx" ON "methodOperationAttribute"("operationId");
+
+ALTER TABLE "methodOperationAttribute" ENABLE ROW LEVEL SECURITY;
+
+
+CREATE POLICY "SELECT" ON "public"."methodOperationAttribute"
+FOR SELECT USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_role()
+ )::text[]
+ )
+);
+
+CREATE POLICY "INSERT" ON "public"."methodOperationAttribute"
+FOR INSERT WITH CHECK (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('parts_create')
+ )::text[]
+ )
+);
+
+CREATE POLICY "UPDATE" ON "public"."methodOperationAttribute"
+FOR UPDATE USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('parts_update')
+ )::text[]
+ )
+);
+
+CREATE POLICY "DELETE" ON "public"."methodOperationAttribute"
+FOR DELETE USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('parts_delete')
+ )::text[]
+ )
+);
+
+CREATE TABLE "quoteOperationAttribute" (
+ "id" TEXT NOT NULL DEFAULT xid(),
+ "name" TEXT NOT NULL,
+ "description" TEXT,
+ "required" BOOLEAN DEFAULT FALSE,
+ "sortOrder" DOUBLE PRECISION NOT NULL DEFAULT 1,
+ "type" "procedureAttributeType" NOT NULL,
+ "unitOfMeasureCode" TEXT,
+ "minValue" DECIMAL,
+ "maxValue" DECIMAL,
+ "listValues" TEXT[],
+ "fileTypes" TEXT[],
+ "operationId" TEXT NOT NULL,
+ "companyId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
+ "createdBy" TEXT NOT NULL,
+ "updatedAt" TIMESTAMP WITH TIME ZONE,
+ "updatedBy" TEXT,
+
+ CONSTRAINT "quoteOperationAttribute_pkey" PRIMARY KEY ("id"),
+ CONSTRAINT "quoteOperationAttribute_operationId_fkey" FOREIGN KEY ("operationId") REFERENCES "quoteOperation"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT "quoteOperationAttribute_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id") ON UPDATE CASCADE,
+ CONSTRAINT "quoteOperationAttribute_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE
+);
+
+CREATE INDEX "quoteOperationAttribute_companyId_idx" ON "quoteOperationAttribute"("companyId");
+CREATE INDEX "quoteOperationAttribute_operationId_idx" ON "quoteOperationAttribute"("operationId");
+
+ALTER TABLE "quoteOperationAttribute" ENABLE ROW LEVEL SECURITY;
+
+
+CREATE POLICY "SELECT" ON "public"."quoteOperationAttribute"
+FOR SELECT USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_role()
+ )::text[]
+ )
+);
+
+CREATE POLICY "INSERT" ON "public"."quoteOperationAttribute"
+FOR INSERT WITH CHECK (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('parts_create')
+ )::text[]
+ )
+);
+
+CREATE POLICY "UPDATE" ON "public"."quoteOperationAttribute"
+FOR UPDATE USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('parts_update')
+ )::text[]
+ )
+);
+
+CREATE POLICY "DELETE" ON "public"."quoteOperationAttribute"
+FOR DELETE USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('parts_delete')
+ )::text[]
+ )
+);
+
+
+CREATE TABLE "jobOperationAttribute" (
+ "id" TEXT NOT NULL DEFAULT xid(),
+ "name" TEXT NOT NULL,
+ "description" TEXT,
+ "required" BOOLEAN DEFAULT FALSE,
+ "sortOrder" DOUBLE PRECISION NOT NULL DEFAULT 1,
+ "type" "procedureAttributeType" NOT NULL,
+ "unitOfMeasureCode" TEXT,
+ "minValue" DECIMAL,
+ "maxValue" DECIMAL,
+ "listValues" TEXT[],
+ "fileTypes" TEXT[],
+ "operationId" TEXT NOT NULL,
+ "companyId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
+ "createdBy" TEXT NOT NULL,
+ "updatedAt" TIMESTAMP WITH TIME ZONE,
+ "updatedBy" TEXT,
+
+ CONSTRAINT "jobOperationAttribute_pkey" PRIMARY KEY ("id"),
+ CONSTRAINT "jobOperationAttribute_operationId_fkey" FOREIGN KEY ("operationId") REFERENCES "jobOperation"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT "jobOperationAttribute_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id") ON UPDATE CASCADE,
+ CONSTRAINT "jobOperationAttribute_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE
+);
+
+CREATE INDEX "jobOperationAttribute_companyId_idx" ON "jobOperationAttribute"("companyId");
+CREATE INDEX "jobOperationAttribute_operationId_idx" ON "jobOperationAttribute"("operationId");
+
+ALTER TABLE "jobOperationAttribute" ENABLE ROW LEVEL SECURITY;
+
+
+CREATE POLICY "SELECT" ON "public"."jobOperationAttribute"
+FOR SELECT USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_role()
+ )::text[]
+ )
+);
+
+CREATE POLICY "INSERT" ON "public"."jobOperationAttribute"
+FOR INSERT WITH CHECK (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('production_create')
+ )::text[]
+ )
+);
+
+CREATE POLICY "UPDATE" ON "public"."jobOperationAttribute"
+FOR UPDATE USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('production_update')
+ )::text[]
+ )
+);
+
+CREATE POLICY "DELETE" ON "public"."jobOperationAttribute"
+FOR DELETE USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('production_delete')
+ )::text[]
+ )
+);
\ No newline at end of file