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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
refactor: services for multi-tenant - parts
Brad Barbinbcb968bc1b43
diff --git a/113.cookie b/113.cookienew file mode 100644index 0000000000..e69de29bb2diff --git a/114.cookie b/114.cookienew file mode 100644index 0000000000..e69de29bb2diff --git a/apps/carbon/app/modules/parts/parts.service.ts b/apps/carbon/app/modules/parts/parts.service.tsindex 4f9bc2e0c9..0488827e73 100644--- a/apps/carbon/app/modules/parts/parts.service.ts+++ b/apps/carbon/app/modules/parts/parts.service.ts@@ -37,9 +37,15 @@ export async function deleteUnitOfMeasure(export async function getPartCost(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: number) {- return client.from("partCost").select("*").eq("partId", id).single();+ return client+ .from("partCost")+ .select("*")+ .eq("partId", id)+ .eq("companyId", companyId)+ .single();}export async function getPartGroup(@@ -51,11 +57,15 @@ export async function getPartGroup(export async function getPartGroups(client: SupabaseClient<Database>,+ companyId: number,args?: GenericQueryFilters & { search: string | null }) {- let query = client.from("partGroup").select("*", {- count: "exact",- });+ let query = client+ .from("partGroup")+ .select("*", {+ count: "exact",+ })+ .eq("companyId", companyId);if (args?.search) {query = query.ilike("name", `%${args.search}%`);@@ -70,60 +80,87 @@ export async function getPartGroups(return query;}-export async function getPartGroupsList(client: SupabaseClient<Database>) {- return client.from("partGroup").select("id, name", { count: "exact" });+export async function getPartGroupsList(+ client: SupabaseClient<Database>,+ companyId: number+) {+ return client+ .from("partGroup")+ .select("id, name", { count: "exact" })+ .eq("companyId", companyId)+ .order("name");}export async function getPartInventory(client: SupabaseClient<Database>,partId: string,+ companyId: number,locationId: string) {return client.from("partInventory").select("*").eq("partId", partId)+ .eq("companyId", companyId).eq("locationId", locationId).maybeSingle();}export async function getPartManufacturing(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: number) {- return client.from("partReplenishment").select("*").eq("partId", id).single();+ return client+ .from("partReplenishment")+ .select("*")+ .eq("partId", id)+ .eq("companyId", companyId)+ .single();}export async function getPartPlanning(client: SupabaseClient<Database>,partId: string,+ companyId: number,locationId: string) {return client.from("partPlanning").select("*").eq("partId", partId)+ .eq("companyId", companyId).eq("locationId", locationId).maybeSingle();}-export async function getPartPurchasing(+export async function getPartReplenishment(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: number) {- return client.from("partReplenishment").select("*").eq("partId", id).single();+ return client+ .from("partReplenishment")+ .select("*")+ .eq("partId", id)+ .eq("companyId", companyId)+ .single();}export async function getParts(client: SupabaseClient<Database>,+ companyId: number,args: GenericQueryFilters & {search: string | null;supplierId: string | null;}) {- let query = client.from("parts").select("*", {- count: "exact",- });+ let query = client+ .from("parts")+ .select("*", {+ count: "exact",+ })+ .eq("companyId", companyId);if (args.search) {query = query.or(@@ -143,13 +180,16 @@ export async function getParts(export async function getPartsList(client: SupabaseClient<Database>,+ companyId: number,replenishmentSystem: PartReplenishmentSystem | null) {let query = client.from("part").select("id, name")+ .eq("companyId", companyId).eq("blocked", false).eq("active", true);+if (replenishmentSystem) {query = query.or(`replenishmentSystem.eq.${replenishmentSystem},replenishmentSystem.eq.Buy and Make`@@ -162,26 +202,35 @@ export async function getPartsList(export async function getPartQuantities(client: SupabaseClient<Database>,partId: string,+ companyId: number,locationId: string) {return client.from("partQuantities").select("*").eq("partId", partId)+ .eq("companyId", companyId).eq("locationId", locationId).maybeSingle();}-export async function getPartSummary(+export async function getPart(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: number) {- return client.from("part").select("*").eq("id", id).single();+ return client+ .from("part")+ .select("*")+ .eq("id", id)+ .eq("companyId", companyId)+ .single();}export async function getPartSuppliers(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: number) {return client.from("partSupplier")@@ -195,18 +244,26 @@ export async function getPartSuppliers(`).eq("active", true)- .eq("partId", id);+ .eq("partId", id)+ .eq("companyId", companyId);}export async function getPartUnitSalePrice(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: number) {- return client.from("partUnitSalePrice").select("*").eq("partId", id).single();+ return client+ .from("partUnitSalePrice")+ .select("*")+ .eq("partId", id)+ .eq("companyId", companyId)+ .single();}export async function getServices(client: SupabaseClient<Database>,+ companyId: number,args: GenericQueryFilters & {search: string | null;type: string | null;@@ -214,9 +271,12 @@ export async function getServices(supplierId: string | null;}) {- let query = client.from("services").select("*", {- count: "exact",- });+ let query = client+ .from("services")+ .select("*", {+ count: "exact",+ })+ .eq("companyId", companyId);if (args.search) {query = query.or(@@ -242,17 +302,28 @@ export async function getServices(return query;}-export async function getService(client: SupabaseClient<Database>, id: string) {- return client.from("services").select("*").eq("id", id).single();+export async function getService(+ client: SupabaseClient<Database>,+ id: string,+ companyId: number+) {+ return client+ .from("services")+ .select("*")+ .eq("id", id)+ .eq("companyId", companyId)+ .single();}export async function getServicesList(client: SupabaseClient<Database>,+ companyId: number,type: ServiceType | null) {let query = client.from("service").select("id, name")+ .eq("companyId", companyId).eq("blocked", false).eq("active", true).order("name");@@ -266,13 +337,15 @@ export async function getServicesList(export async function getServiceSuppliers(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: number) {return client.from("serviceSupplier").select(`id, supplier(id, name), customFields, supplierServiceId`)- .eq("active", true)- .eq("serviceId", id);+ .eq("serviceId", id)+ .eq("companyId", companyId)+ .eq("active", true);}export async function getShelvesList(@@ -289,18 +362,28 @@ export async function getShelvesList(export async function getUnitOfMeasure(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: number) {- return client.from("unitOfMeasure").select("*").eq("id", id).single();+ return client+ .from("unitOfMeasure")+ .select("*")+ .eq("id", id)+ .eq("companyId", companyId)+ .single();}export async function getUnitOfMeasures(client: SupabaseClient<Database>,+ companyId: number,args: GenericQueryFilters & { search: string | null }) {- let query = client.from("unitOfMeasure").select("*", {- count: "exact",- });+ let query = client+ .from("unitOfMeasure")+ .select("*", {+ count: "exact",+ })+ .eq("companyId", companyId);if (args.search) {query = query.or(`name.ilike.%${args.search}%,code.ilike.%${args.search}%`);@@ -312,15 +395,23 @@ export async function getUnitOfMeasures(return query;}-export async function getUnitOfMeasuresList(client: SupabaseClient<Database>) {- return client.from("unitOfMeasure").select("name, code").order("name");+export async function getUnitOfMeasuresList(+ client: SupabaseClient<Database>,+ companyId: number+) {+ return client+ .from("unitOfMeasure")+ .select("name, code")+ .eq("companyId", companyId)+ .order("name");}export async function insertShelf(client: SupabaseClient<Database>,shelfId: string,locationId: string,- userId: string+ userId: string,+ companyId: number) {const shelfLookup = await client.from("shelf")@@ -341,6 +432,7 @@ export async function insertShelf(.insert([{id: shelfId,+ companyId,locationId,createdBy: userId,},@@ -391,6 +483,7 @@ export async function upsertPartInventory(client: SupabaseClient<Database>,partInventory:| (z.infer<typeof partInventoryValidator> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -463,6 +556,7 @@ export async function upsertPartGroup(client: SupabaseClient<Database>,partGroup:| (Omit<z.infer<typeof partGroupValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -490,6 +584,7 @@ export async function upsertPartSupplier(client: SupabaseClient<Database>,partSupplier:| (Omit<z.infer<typeof partSupplierValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -531,6 +626,7 @@ export async function upsertService(client: SupabaseClient<Database>,service:| (z.infer<typeof serviceValidator> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -556,6 +652,7 @@ export async function upsertServiceSupplier(client: SupabaseClient<Database>,serviceSupplier:| (Omit<z.infer<typeof serviceSupplierValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -584,6 +681,7 @@ export async function upsertUnitOfMeasure(client: SupabaseClient<Database>,unitOfMeasure:| (Omit<z.infer<typeof unitOfMeasureValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})diff --git a/apps/carbon/app/modules/parts/types.ts b/apps/carbon/app/modules/parts/types.tsindex 77ba987a09..7e6ce22bef 100644--- a/apps/carbon/app/modules/parts/types.ts+++ b/apps/carbon/app/modules/parts/types.ts@@ -1,14 +1,14 @@import type { Database } from "@carbon/database";import type {+ getPart,getPartCost,getPartGroups,getPartGroupsList,getPartQuantities,- getParts,- getPartSummary,getPartSuppliers,- getServices,+ getParts,getServiceSuppliers,+ getServices,getUnitOfMeasure,getUnitOfMeasuresList,} from "./parts.service";@@ -39,7 +39,7 @@ export type PartReplenishmentSystem =Database["public"]["Enums"]["partReplenishmentSystem"];export type PartSummary = NonNullable<- Awaited<ReturnType<typeof getPartSummary>>+ Awaited<ReturnType<typeof getPart>>>["data"];export type PartSupplier = NonNullable<diff --git a/apps/carbon/app/modules/parts/ui/Part/PartInventoryForm.tsx b/apps/carbon/app/modules/parts/ui/Part/PartInventoryForm.tsxindex c1c668efad..27efaa1f02 100644--- a/apps/carbon/app/modules/parts/ui/Part/PartInventoryForm.tsx+++ b/apps/carbon/app/modules/parts/ui/Part/PartInventoryForm.tsx@@ -87,6 +87,7 @@ const PartInventoryForm = ({onCreateOption={async (option) => {const response = await supabase?.from("shelf").insert({id: option,+ companyId: user.company.id,locationId: initialValues.locationId,createdBy: user.id,});diff --git a/apps/carbon/app/routes/api+/parts.groups.ts b/apps/carbon/app/routes/api+/parts.groups.tsindex 1240c05349..4cbdc23054 100644--- a/apps/carbon/app/routes/api+/parts.groups.ts+++ b/apps/carbon/app/routes/api+/parts.groups.ts@@ -4,7 +4,7 @@ import { getPartGroupsList } from "~/modules/parts";import { requirePermissions } from "~/services/auth/auth.server";export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {});+ const { client, companyId } = await requirePermissions(request, {});- return json(await getPartGroupsList(authorized.client));+ return json(await getPartGroupsList(client, companyId));}diff --git a/apps/carbon/app/routes/api+/parts.list.ts b/apps/carbon/app/routes/api+/parts.list.tsindex fe74fa89be..21d7a44ab7 100644--- a/apps/carbon/app/routes/api+/parts.list.ts+++ b/apps/carbon/app/routes/api+/parts.list.ts@@ -7,7 +7,7 @@ import { flash } from "~/services/session.server";import { error } from "~/utils/result";export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {});+ const { client, companyId } = await requirePermissions(request, {});const url = new URL(request.url);const searchParams = new URLSearchParams(url.search);@@ -15,7 +15,7 @@ export async function loader({ request }: LoaderFunctionArgs) {"replenishmentSystem") as PartReplenishmentSystem | null;- const parts = await getPartsList(authorized.client, replenishmentSystem);+ const parts = await getPartsList(client, companyId, replenishmentSystem);if (parts.error) {return json(parts,diff --git a/apps/carbon/app/routes/api+/parts.services.ts b/apps/carbon/app/routes/api+/parts.services.tsindex 1ffcda38f2..46bf3a9043 100644--- a/apps/carbon/app/routes/api+/parts.services.ts+++ b/apps/carbon/app/routes/api+/parts.services.ts@@ -7,7 +7,7 @@ import { flash } from "~/services/session.server";import { error } from "~/utils/result";export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});@@ -15,7 +15,7 @@ export async function loader({ request }: LoaderFunctionArgs) {const searchParams = new URLSearchParams(url.search);const type = searchParams.get("type") as ServiceType | null;- const services = await getServicesList(authorized.client, type);+ const services = await getServicesList(client, companyId, type);if (services.error) {return json(services,diff --git a/apps/carbon/app/routes/api+/parts.uom.ts b/apps/carbon/app/routes/api+/parts.uom.tsdeleted file mode 100644index 7853fd6484..0000000000--- a/apps/carbon/app/routes/api+/parts.uom.ts+++ /dev/null@@ -1,10 +0,0 @@-import type { LoaderFunctionArgs } from "@remix-run/node";-import { json } from "@remix-run/node";-import { getUnitOfMeasuresList } from "~/modules/parts";-import { requirePermissions } from "~/services/auth/auth.server";--export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {});-- return json(getUnitOfMeasuresList(authorized.client));-}diff --git a/apps/carbon/app/routes/api+/parts.uoms.ts b/apps/carbon/app/routes/api+/parts.uoms.tsindex 1f6cb11ae6..de2bb8810f 100644--- a/apps/carbon/app/routes/api+/parts.uoms.ts+++ b/apps/carbon/app/routes/api+/parts.uoms.ts@@ -4,7 +4,7 @@ import { getUnitOfMeasuresList } from "~/modules/parts";import { requirePermissions } from "~/services/auth/auth.server";export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {});+ const { client, companyId } = await requirePermissions(request, {});- return json(await getUnitOfMeasuresList(authorized.client));+ return json(getUnitOfMeasuresList(client, companyId));}diff --git a/apps/carbon/app/routes/x+/accounting+/groups.inventory.tsx b/apps/carbon/app/routes/x+/accounting+/groups.inventory.tsxindex 3102afb0fd..aea5f99163 100644--- a/apps/carbon/app/routes/x+/accounting+/groups.inventory.tsx+++ b/apps/carbon/app/routes/x+/accounting+/groups.inventory.tsx@@ -40,7 +40,7 @@ export async function loader({ request }: LoaderFunctionArgs) {sorts,filters,}),- getPartGroupsList(client),+ getPartGroupsList(client, companyId),getLocationsList(client, companyId),]);if (inventoryGroups.error) {diff --git a/apps/carbon/app/routes/x+/accounting+/groups.purchasing.tsx b/apps/carbon/app/routes/x+/accounting+/groups.purchasing.tsxindex fc72866cf3..f0e6a76a2c 100644--- a/apps/carbon/app/routes/x+/accounting+/groups.purchasing.tsx+++ b/apps/carbon/app/routes/x+/accounting+/groups.purchasing.tsx@@ -23,7 +23,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: ["accounting", "purchasing"],});@@ -39,7 +39,7 @@ export async function loader({ request }: LoaderFunctionArgs) {sorts,filters,}),- getPartGroupsList(client),+ getPartGroupsList(client, companyId),getSupplierTypesList(client),]);if (purchasingGroups.error) {diff --git a/apps/carbon/app/routes/x+/accounting+/groups.sales.tsx b/apps/carbon/app/routes/x+/accounting+/groups.sales.tsxindex 03e85b46e2..78e4fb01d5 100644--- a/apps/carbon/app/routes/x+/accounting+/groups.sales.tsx+++ b/apps/carbon/app/routes/x+/accounting+/groups.sales.tsx@@ -23,7 +23,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: ["accounting", "sales"],});@@ -39,7 +39,7 @@ export async function loader({ request }: LoaderFunctionArgs) {sorts,filters,}),- getPartGroupsList(client),+ getPartGroupsList(client, companyId),getCustomerTypesList(client),]);if (salesGroups.error) {diff --git a/apps/carbon/app/routes/x+/part+/$partId.costing.tsx b/apps/carbon/app/routes/x+/part+/$partId.costing.tsxindex 79520a8d22..0ff7020b9a 100644--- a/apps/carbon/app/routes/x+/part+/$partId.costing.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.costing.tsx@@ -17,7 +17,7 @@ import { path } from "~/utils/path";import { error, success } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});@@ -25,7 +25,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {if (!partId) throw new Error("Could not find partId");const [partCost, accounts] = await Promise.all([- getPartCost(client, partId),+ getPartCost(client, partId, companyId),getAccountsList(client),]);diff --git a/apps/carbon/app/routes/x+/part+/$partId.inventory.tsx b/apps/carbon/app/routes/x+/part+/$partId.inventory.tsxindex 0ae6539269..053c0e25f9 100644--- a/apps/carbon/app/routes/x+/part+/$partId.inventory.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.inventory.tsx@@ -63,13 +63,14 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}let [partInventory, shelves] = await Promise.all([- getPartInventory(client, partId, locationId),+ getPartInventory(client, partId, companyId, locationId),getShelvesList(client, locationId),]);if (partInventory.error || !partInventory.data) {const insertPartInventory = await upsertPartInventory(client, {partId,+ companyId,locationId,customFields: {},createdBy: userId,@@ -85,7 +86,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {);}- partInventory = await getPartInventory(client, partId, locationId);+ partInventory = await getPartInventory(+ client,+ partId,+ companyId,+ locationId+ );if (partInventory.error || !partInventory.data) {throw redirect(path.to.part(partId),@@ -104,7 +110,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {);}- const quantities = await getPartQuantities(client, partId, locationId);+ const quantities = await getPartQuantities(+ client,+ partId,+ companyId,+ locationId+ );if (quantities.error || !quantities.data) {throw redirect(path.to.parts,diff --git a/apps/carbon/app/routes/x+/part+/$partId.manufacturing.tsx b/apps/carbon/app/routes/x+/part+/$partId.manufacturing.tsxindex dc97899ea3..03c539840e 100644--- a/apps/carbon/app/routes/x+/part+/$partId.manufacturing.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.manufacturing.tsx@@ -16,14 +16,18 @@ import { path } from "~/utils/path";import { error, success } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});const { partId } = params;if (!partId) throw new Error("Could not find partId");- const partManufacturing = await getPartManufacturing(client, partId);+ const partManufacturing = await getPartManufacturing(+ client,+ partId,+ companyId+ );if (partManufacturing.error) {throw redirect(diff --git a/apps/carbon/app/routes/x+/part+/$partId.planning.tsx b/apps/carbon/app/routes/x+/part+/$partId.planning.tsxindex ac15a16a9d..f3d7cceb70 100644--- a/apps/carbon/app/routes/x+/part+/$partId.planning.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.planning.tsx@@ -60,7 +60,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {locationId = locations.data?.[0].id as string;}- let partPlanning = await getPartPlanning(client, partId, locationId);+ let partPlanning = await getPartPlanning(+ client,+ partId,+ companyId,+ locationId+ );if (partPlanning.error || !partPlanning.data) {const insertPartPlanning = await upsertPartPlanning(client, {@@ -80,7 +85,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {);}- partPlanning = await getPartPlanning(client, partId, locationId);+ partPlanning = await getPartPlanning(client, partId, companyId, locationId);if (partPlanning.error || !partPlanning.data) {throw redirect(path.to.part(partId),diff --git a/apps/carbon/app/routes/x+/part+/$partId.purchasing.tsx b/apps/carbon/app/routes/x+/part+/$partId.purchasing.tsxindex 973fedc981..fa8faf5254 100644--- a/apps/carbon/app/routes/x+/part+/$partId.purchasing.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.purchasing.tsx@@ -4,7 +4,7 @@ import { json, redirect } from "@remix-run/node";import { useLoaderData } from "@remix-run/react";import {PartPurchasingForm,- getPartPurchasing,+ getPartReplenishment,partPurchasingValidator,upsertPartPurchasing,} from "~/modules/parts";@@ -15,14 +15,14 @@ import { path } from "~/utils/path";import { error, success } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});const { partId } = params;if (!partId) throw new Error("Could not find partId");- const partPurchasing = await getPartPurchasing(client, partId);+ const partPurchasing = await getPartReplenishment(client, partId, companyId);if (partPurchasing.error) {throw redirect(diff --git a/apps/carbon/app/routes/x+/part+/$partId.sale-price.tsx b/apps/carbon/app/routes/x+/part+/$partId.sale-price.tsxindex fe7cde4297..86f685b790 100644--- a/apps/carbon/app/routes/x+/part+/$partId.sale-price.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.sale-price.tsx@@ -16,7 +16,7 @@ import { path } from "~/utils/path";import { error, success } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});@@ -24,7 +24,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {if (!partId) throw new Error("Could not find partId");const [partUnitSalePrice] = await Promise.all([- getPartUnitSalePrice(client, partId),+ getPartUnitSalePrice(client, partId, companyId),]);if (partUnitSalePrice.error) {diff --git a/apps/carbon/app/routes/x+/part+/$partId.suppliers.new.tsx b/apps/carbon/app/routes/x+/part+/$partId.suppliers.new.tsxindex 36ffa52af7..0dfdf295a4 100644--- a/apps/carbon/app/routes/x+/part+/$partId.suppliers.new.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.suppliers.new.tsx@@ -16,7 +16,7 @@ import { error } from "~/utils/result";export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "parts",});@@ -34,6 +34,7 @@ export async function action({ request, params }: ActionFunctionArgs) {const createPartSupplier = await upsertPartSupplier(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/part+/$partId.suppliers.tsx b/apps/carbon/app/routes/x+/part+/$partId.suppliers.tsxindex 1ccb35ca8b..b80f928ee5 100644--- a/apps/carbon/app/routes/x+/part+/$partId.suppliers.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.suppliers.tsx@@ -8,14 +8,16 @@ import { path } from "~/utils/path";import { error } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});const { partId } = params;if (!partId) throw new Error("Could not find partId");- const [partSuppliers] = await Promise.all([getPartSuppliers(client, partId)]);+ const [partSuppliers] = await Promise.all([+ getPartSuppliers(client, partId, companyId),+ ]);if (partSuppliers.error) {throw redirect(diff --git a/apps/carbon/app/routes/x+/part+/$partId.tsx b/apps/carbon/app/routes/x+/part+/$partId.tsxindex 654fad0de0..7bb48c7d7b 100644--- a/apps/carbon/app/routes/x+/part+/$partId.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.tsx@@ -1,21 +1,21 @@import type { LoaderFunctionArgs } from "@remix-run/node";import { json, redirect } from "@remix-run/node";import { Outlet } from "@remix-run/react";-import { PartHeader, PartSidebar, getPartSummary } from "~/modules/parts";+import { PartHeader, PartSidebar, getPart } from "~/modules/parts";import { requirePermissions } from "~/services/auth/auth.server";import { flash } from "~/services/session.server";import { path } from "~/utils/path";import { error } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});const { partId } = params;if (!partId) throw new Error("Could not find partId");- const [partSummary] = await Promise.all([getPartSummary(client, partId)]);+ const [partSummary] = await Promise.all([getPart(client, partId, companyId)]);if (partSummary.error) {throw redirect(diff --git a/apps/carbon/app/routes/x+/part+/_layout.tsx b/apps/carbon/app/routes/x+/part+/_layout.tsxindex 0c3139c090..0170e0b22b 100644--- a/apps/carbon/app/routes/x+/part+/_layout.tsx+++ b/apps/carbon/app/routes/x+/part+/_layout.tsx@@ -23,7 +23,7 @@ export async function loader({ request }: LoaderFunctionArgs) {});const [unitOfMeasures, locations] = await Promise.all([- getUnitOfMeasuresList(client),+ getUnitOfMeasuresList(client, companyId),getLocationsList(client, companyId),]);diff --git a/apps/carbon/app/routes/x+/parts+/groups.new.tsx b/apps/carbon/app/routes/x+/parts+/groups.new.tsxindex 42d9cd4553..e39d01cc2a 100644--- a/apps/carbon/app/routes/x+/parts+/groups.new.tsx+++ b/apps/carbon/app/routes/x+/parts+/groups.new.tsx@@ -24,7 +24,7 @@ export async function loader({ request }: LoaderFunctionArgs) {export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "parts",});@@ -41,6 +41,7 @@ export async function action({ request }: ActionFunctionArgs) {const insertPartGroup = await upsertPartGroup(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/parts+/groups.tsx b/apps/carbon/app/routes/x+/parts+/groups.tsxindex 615dd059b7..9aa0148c64 100644--- a/apps/carbon/app/routes/x+/parts+/groups.tsx+++ b/apps/carbon/app/routes/x+/parts+/groups.tsx@@ -17,7 +17,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",role: "employee",});@@ -29,7 +29,7 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [partGroups, accounts] = await Promise.all([- getPartGroups(client, {+ getPartGroups(client, companyId, {limit,offset,sorts,diff --git a/apps/carbon/app/routes/x+/parts+/search.tsx b/apps/carbon/app/routes/x+/parts+/search.tsxindex 02fbe3911e..6db2e69476 100644--- a/apps/carbon/app/routes/x+/parts+/search.tsx+++ b/apps/carbon/app/routes/x+/parts+/search.tsx@@ -10,7 +10,7 @@ import { getGenericQueryFilters } from "~/utils/query";import { error } from "~/utils/result";export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});@@ -23,7 +23,7 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [parts, partGroups] = await Promise.all([- getParts(client, {+ getParts(client, companyId, {search,supplierId,limit,@@ -31,7 +31,7 @@ export async function loader({ request }: LoaderFunctionArgs) {sorts,filters,}),- getPartGroupsList(client),+ getPartGroupsList(client, companyId),]);if (parts.error) {diff --git a/apps/carbon/app/routes/x+/parts+/services.tsx b/apps/carbon/app/routes/x+/parts+/services.tsxindex 578c438efd..728320098f 100644--- a/apps/carbon/app/routes/x+/parts+/services.tsx+++ b/apps/carbon/app/routes/x+/parts+/services.tsx@@ -16,7 +16,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});@@ -31,7 +31,7 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [services, partGroups] = await Promise.all([- getServices(client, {+ getServices(client, companyId, {search,type,group,@@ -41,7 +41,7 @@ export async function loader({ request }: LoaderFunctionArgs) {sorts,filters,}),- getPartGroupsList(client),+ getPartGroupsList(client, companyId),]);if (services.error) {diff --git a/apps/carbon/app/routes/x+/parts+/uom.$uomId.tsx b/apps/carbon/app/routes/x+/parts+/uom.$uomId.tsxindex 435fe32dd0..24ee529b8a 100644--- a/apps/carbon/app/routes/x+/parts+/uom.$uomId.tsx+++ b/apps/carbon/app/routes/x+/parts+/uom.$uomId.tsx@@ -16,7 +16,7 @@ import { getParams, path } from "~/utils/path";import { error, success } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",role: "employee",});@@ -24,7 +24,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { uomId } = params;if (!uomId) throw notFound("uomId not found");- const unitOfMeasure = await getUnitOfMeasure(client, uomId);+ const unitOfMeasure = await getUnitOfMeasure(client, uomId, companyId);return json({unitOfMeasure: unitOfMeasure?.data ?? null,diff --git a/apps/carbon/app/routes/x+/parts+/uom.delete.$uomId.tsx b/apps/carbon/app/routes/x+/parts+/uom.delete.$uomId.tsxindex 57d252f4c9..9e43013ef3 100644--- a/apps/carbon/app/routes/x+/parts+/uom.delete.$uomId.tsx+++ b/apps/carbon/app/routes/x+/parts+/uom.delete.$uomId.tsx@@ -10,13 +10,13 @@ import { getParams, path } from "~/utils/path";import { error, success } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});const { uomId } = params;if (!uomId) throw notFound("uomId not found");- const unitOfMeasure = await getUnitOfMeasure(client, uomId);+ const unitOfMeasure = await getUnitOfMeasure(client, uomId, companyId);if (unitOfMeasure.error) {throw redirect(`${path.to.uoms}?${getParams(request)}`,diff --git a/apps/carbon/app/routes/x+/parts+/uom.new.tsx b/apps/carbon/app/routes/x+/parts+/uom.new.tsxindex 649e47b702..46938a868d 100644--- a/apps/carbon/app/routes/x+/parts+/uom.new.tsx+++ b/apps/carbon/app/routes/x+/parts+/uom.new.tsx@@ -24,7 +24,7 @@ export async function loader({ request }: LoaderFunctionArgs) {export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "parts",});@@ -37,11 +37,11 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const { name, code } = validation.data;+ const { id, ...data } = validation.data;const insertUnitOfMeasure = await upsertUnitOfMeasure(client, {- name,- code,+ ...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/parts+/uom.tsx b/apps/carbon/app/routes/x+/parts+/uom.tsxindex d542c2cdbb..50ecc81092 100644--- a/apps/carbon/app/routes/x+/parts+/uom.tsx+++ b/apps/carbon/app/routes/x+/parts+/uom.tsx@@ -14,7 +14,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",role: "employee",});@@ -26,7 +26,13 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);return json(- await getUnitOfMeasures(client, { search, limit, offset, sorts, filters })+ await getUnitOfMeasures(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters,+ }));}diff --git a/apps/carbon/app/routes/x+/receipt+/_layout.tsx b/apps/carbon/app/routes/x+/receipt+/_layout.tsxindex 3cf45ce2a9..03b5de1045 100644--- a/apps/carbon/app/routes/x+/receipt+/_layout.tsx+++ b/apps/carbon/app/routes/x+/receipt+/_layout.tsx@@ -23,7 +23,7 @@ export async function loader({ request }: LoaderFunctionArgs) {});const [unitOfMeasures, locations] = await Promise.all([- getUnitOfMeasuresList(client),+ getUnitOfMeasuresList(client, companyId),getLocationsList(client, companyId),]);diff --git a/apps/carbon/app/routes/x+/service+/$serviceId.suppliers.new.tsx b/apps/carbon/app/routes/x+/service+/$serviceId.suppliers.new.tsxindex 3fa1f45543..3c62bacba4 100644--- a/apps/carbon/app/routes/x+/service+/$serviceId.suppliers.new.tsx+++ b/apps/carbon/app/routes/x+/service+/$serviceId.suppliers.new.tsx@@ -16,7 +16,7 @@ import { error } from "~/utils/result";export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "parts",});@@ -36,6 +36,7 @@ export async function action({ request, params }: ActionFunctionArgs) {const createServiceSupplier = await upsertServiceSupplier(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/service+/$serviceId.suppliers.tsx b/apps/carbon/app/routes/x+/service+/$serviceId.suppliers.tsxindex 2429ec0d81..b23bb56ef3 100644--- a/apps/carbon/app/routes/x+/service+/$serviceId.suppliers.tsx+++ b/apps/carbon/app/routes/x+/service+/$serviceId.suppliers.tsx@@ -8,7 +8,7 @@ import { path } from "~/utils/path";import { error } from "~/utils/result";export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});@@ -16,7 +16,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {if (!serviceId) throw new Error("Could not find serviceId");const [serviceSuppliers] = await Promise.all([- getServiceSuppliers(client, serviceId),+ getServiceSuppliers(client, serviceId, companyId),]);if (serviceSuppliers.error) {diff --git a/apps/carbon/app/routes/x+/service+/$serviceId.tsx b/apps/carbon/app/routes/x+/service+/$serviceId.tsxindex 1be57cdfa0..93c6719495 100644--- a/apps/carbon/app/routes/x+/service+/$serviceId.tsx+++ b/apps/carbon/app/routes/x+/service+/$serviceId.tsx@@ -14,14 +14,16 @@ export const handle: Handle = {};export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "parts",});const { serviceId } = params;if (!serviceId) throw new Error("Could not find serviceId");- const [service] = await Promise.all([getService(client, serviceId)]);+ const [service] = await Promise.all([+ getService(client, serviceId, companyId),+ ]);if (service.error) {throw redirect(diff --git a/apps/carbon/app/routes/x+/service+/_layout.tsx b/apps/carbon/app/routes/x+/service+/_layout.tsxindex fc8e375449..a01fa59836 100644--- a/apps/carbon/app/routes/x+/service+/_layout.tsx+++ b/apps/carbon/app/routes/x+/service+/_layout.tsx@@ -23,7 +23,7 @@ export async function loader({ request }: LoaderFunctionArgs) {});const [partGroups, locations] = await Promise.all([- getPartGroupsList(client),+ getPartGroupsList(client, companyId),getLocationsList(client, companyId),]);diff --git a/apps/carbon/app/routes/x+/service+/new.tsx b/apps/carbon/app/routes/x+/service+/new.tsxindex 94354f9660..bdf7d1821a 100644--- a/apps/carbon/app/routes/x+/service+/new.tsx+++ b/apps/carbon/app/routes/x+/service+/new.tsx@@ -17,7 +17,7 @@ export const handle: Handle = {export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "parts",});@@ -30,6 +30,7 @@ export async function action({ request }: ActionFunctionArgs) {const createService = await upsertService(client, {...validation.data,+ companyId,active: true,createdBy: userId,customFields: setCustomFields(formData),diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 21d9233b53..b3da6c6a93 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -5115,24 +5115,17 @@ export type Database = {},{foreignKeyName: "partCost_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "partCost_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partCost_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partGroup_createdBy_fkey"@@ -5395,24 +5388,17 @@ export type Database = {},{foreignKeyName: "partInventory_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partInventory_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "partInventory_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partInventory_shelfId_fkey"@@ -5534,24 +5520,17 @@ export type Database = {},{foreignKeyName: "partLedger_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partLedger_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "partLedger_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partLedger_shelfId_fkey"@@ -5822,24 +5801,17 @@ export type Database = {},{foreignKeyName: "partPlanning_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partPlanning_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "partPlanning_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partPlanning_updatedBy_fkey"@@ -5970,24 +5942,17 @@ export type Database = {},{foreignKeyName: "partReplenishment_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "partReplenishment_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partReplenishment_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partReplenishment_preferredSupplierId_fkey"@@ -6151,24 +6116,17 @@ export type Database = {},{foreignKeyName: "partSupplier_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partSupplier_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "partSupplier_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partSupplier_supplierId_fkey"@@ -6326,24 +6284,17 @@ export type Database = {},{foreignKeyName: "partUnitSalePrice_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partUnitSalePrice_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "partUnitSalePrice_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partUnitSalePrice_salesUnitOfMeasureId_fkey"@@ -7645,24 +7596,17 @@ export type Database = {},{foreignKeyName: "purchaseInvoiceLines_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseInvoiceLines_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "purchaseInvoiceLines_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseInvoiceLines_purchaseOrderId_fkey"@@ -7708,17 +7652,17 @@ export type Database = {},{foreignKeyName: "purchaseInvoiceLines_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseInvoiceLines_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseInvoiceLines_shelfId_fkey"@@ -8542,24 +8486,17 @@ export type Database = {},{foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_purchaseOrderId_fkey"@@ -8591,17 +8528,17 @@ export type Database = {},{foreignKeyName: "purchaseOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_shelfId_fkey"@@ -9295,6 +9232,7 @@ export type Database = {}quoteAssembly: {Row: {+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -9310,6 +9248,7 @@ export type Database = {updatedBy: string | null}Insert: {+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -9325,6 +9264,7 @@ export type Database = {updatedBy?: string | null}Update: {+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -9340,6 +9280,13 @@ export type Database = {updatedBy?: string | null}Relationships: [+ {+ foreignKeyName: "quoteAssembly_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "company"+ referencedColumns: ["id"]+ },{foreignKeyName: "quoteAssembly_createdBy_fkey"columns: ["createdBy"]@@ -9375,6 +9322,20 @@ export type Database = {referencedRelation: "quoteAssembly"referencedColumns: ["id"]},+ {+ foreignKeyName: "quoteAssembly_partId_fkey"+ columns: ["partId", "companyId"]+ isOneToOne: false+ referencedRelation: "part"+ referencedColumns: ["id", "companyId"]+ },+ {+ foreignKeyName: "quoteAssembly_partId_fkey"+ columns: ["partId", "companyId"]+ isOneToOne: false+ referencedRelation: "parts"+ referencedColumns: ["id", "companyId"]+ },{foreignKeyName: "quoteAssembly_quoteId_fkey"columns: ["quoteId"]@@ -9410,6 +9371,13 @@ export type Database = {referencedRelation: "quoteLines"referencedColumns: ["id"]},+ {+ foreignKeyName: "quoteAssembly_unitOfMeasureCode_fkey"+ columns: ["unitOfMeasureCode", "companyId"]+ isOneToOne: false+ referencedRelation: "unitOfMeasure"+ referencedColumns: ["code", "companyId"]+ },{foreignKeyName: "quoteAssembly_updatedBy_fkey"columns: ["updatedBy"]@@ -9595,24 +9563,17 @@ export type Database = {},{foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteLine_quoteId_fkey"@@ -9814,6 +9775,7 @@ export type Database = {}quoteMaterial: {Row: {+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -9830,6 +9792,7 @@ export type Database = {updatedBy: string | null}Insert: {+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -9846,6 +9809,7 @@ export type Database = {updatedBy?: string | null}Update: {+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -9862,6 +9826,13 @@ export type Database = {updatedBy?: string | null}Relationships: [+ {+ foreignKeyName: "quoteMaterial_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "company"+ referencedColumns: ["id"]+ },{foreignKeyName: "quoteMaterial_createdBy_fkey"columns: ["createdBy"]@@ -9892,24 +9863,17 @@ export type Database = {},{foreignKeyName: "quoteMaterial_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "quoteMaterial_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteMaterial_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteMaterial_quoteId_fkey"@@ -9953,6 +9917,13 @@ export type Database = {referencedRelation: "quoteOperation"referencedColumns: ["id"]},+ {+ foreignKeyName: "quoteMaterial_unitOfMeasureCode_fkey"+ columns: ["unitOfMeasureCode", "companyId"]+ isOneToOne: false+ referencedRelation: "unitOfMeasure"+ referencedColumns: ["code", "companyId"]+ },{foreignKeyName: "quoteMaterial_updatedBy_fkey"columns: ["updatedBy"]@@ -9985,6 +9956,7 @@ export type Database = {}quoteOperation: {Row: {+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -10005,6 +9977,7 @@ export type Database = {workCellTypeId: string}Insert: {+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -10025,6 +9998,7 @@ export type Database = {workCellTypeId: string}Update: {+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -10045,6 +10019,13 @@ export type Database = {workCellTypeId?: string}Relationships: [+ {+ foreignKeyName: "quoteOperation_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "company"+ referencedColumns: ["id"]+ },{foreignKeyName: "quoteOperation_createdBy_fkey"columns: ["createdBy"]@@ -10500,24 +10481,17 @@ export type Database = {},{foreignKeyName: "receiptLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "receiptLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "receiptLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "receiptLine_receiptId_fkey"@@ -10923,24 +10897,17 @@ export type Database = {},{foreignKeyName: "requestForQuoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "requestForQuoteLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "requestForQuoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "requestForQuoteLine_requestForQuoteId_fkey"@@ -11739,24 +11706,17 @@ export type Database = {},{foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_salesOrderId_fkey"@@ -11774,17 +11734,17 @@ export type Database = {},{foreignKeyName: "salesOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_shelfId_fkey"@@ -12678,17 +12638,17 @@ export type Database = {},{foreignKeyName: "serviceSupplier_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "serviceSupplier_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "serviceSupplier_supplierId_fkey"@@ -16698,24 +16658,17 @@ export type Database = {},{foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_purchaseOrderId_fkey"@@ -16747,17 +16700,17 @@ export type Database = {},{foreignKeyName: "purchaseOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_shelfId_fkey"@@ -17141,24 +17094,17 @@ export type Database = {},{foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteLine_quoteId_fkey"@@ -17844,24 +17790,17 @@ export type Database = {},{foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_salesOrderId_fkey"@@ -17879,17 +17818,17 @@ export type Database = {},{foreignKeyName: "salesOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_shelfId_fkey"diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex 21d9233b53..b3da6c6a93 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -5115,24 +5115,17 @@ export type Database = {},{foreignKeyName: "partCost_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "partCost_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partCost_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partGroup_createdBy_fkey"@@ -5395,24 +5388,17 @@ export type Database = {},{foreignKeyName: "partInventory_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partInventory_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "partInventory_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partInventory_shelfId_fkey"@@ -5534,24 +5520,17 @@ export type Database = {},{foreignKeyName: "partLedger_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partLedger_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "partLedger_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partLedger_shelfId_fkey"@@ -5822,24 +5801,17 @@ export type Database = {},{foreignKeyName: "partPlanning_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partPlanning_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "partPlanning_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partPlanning_updatedBy_fkey"@@ -5970,24 +5942,17 @@ export type Database = {},{foreignKeyName: "partReplenishment_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "partReplenishment_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partReplenishment_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partReplenishment_preferredSupplierId_fkey"@@ -6151,24 +6116,17 @@ export type Database = {},{foreignKeyName: "partSupplier_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partSupplier_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "partSupplier_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partSupplier_supplierId_fkey"@@ -6326,24 +6284,17 @@ export type Database = {},{foreignKeyName: "partUnitSalePrice_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partUnitSalePrice_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "partUnitSalePrice_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "partUnitSalePrice_salesUnitOfMeasureId_fkey"@@ -7645,24 +7596,17 @@ export type Database = {},{foreignKeyName: "purchaseInvoiceLines_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseInvoiceLines_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "purchaseInvoiceLines_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseInvoiceLines_purchaseOrderId_fkey"@@ -7708,17 +7652,17 @@ export type Database = {},{foreignKeyName: "purchaseInvoiceLines_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseInvoiceLines_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseInvoiceLines_shelfId_fkey"@@ -8542,24 +8486,17 @@ export type Database = {},{foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_purchaseOrderId_fkey"@@ -8591,17 +8528,17 @@ export type Database = {},{foreignKeyName: "purchaseOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_shelfId_fkey"@@ -9295,6 +9232,7 @@ export type Database = {}quoteAssembly: {Row: {+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -9310,6 +9248,7 @@ export type Database = {updatedBy: string | null}Insert: {+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -9325,6 +9264,7 @@ export type Database = {updatedBy?: string | null}Update: {+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -9340,6 +9280,13 @@ export type Database = {updatedBy?: string | null}Relationships: [+ {+ foreignKeyName: "quoteAssembly_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "company"+ referencedColumns: ["id"]+ },{foreignKeyName: "quoteAssembly_createdBy_fkey"columns: ["createdBy"]@@ -9375,6 +9322,20 @@ export type Database = {referencedRelation: "quoteAssembly"referencedColumns: ["id"]},+ {+ foreignKeyName: "quoteAssembly_partId_fkey"+ columns: ["partId", "companyId"]+ isOneToOne: false+ referencedRelation: "part"+ referencedColumns: ["id", "companyId"]+ },+ {+ foreignKeyName: "quoteAssembly_partId_fkey"+ columns: ["partId", "companyId"]+ isOneToOne: false+ referencedRelation: "parts"+ referencedColumns: ["id", "companyId"]+ },{foreignKeyName: "quoteAssembly_quoteId_fkey"columns: ["quoteId"]@@ -9410,6 +9371,13 @@ export type Database = {referencedRelation: "quoteLines"referencedColumns: ["id"]},+ {+ foreignKeyName: "quoteAssembly_unitOfMeasureCode_fkey"+ columns: ["unitOfMeasureCode", "companyId"]+ isOneToOne: false+ referencedRelation: "unitOfMeasure"+ referencedColumns: ["code", "companyId"]+ },{foreignKeyName: "quoteAssembly_updatedBy_fkey"columns: ["updatedBy"]@@ -9595,24 +9563,17 @@ export type Database = {},{foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteLine_quoteId_fkey"@@ -9814,6 +9775,7 @@ export type Database = {}quoteMaterial: {Row: {+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -9830,6 +9792,7 @@ export type Database = {updatedBy: string | null}Insert: {+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -9846,6 +9809,7 @@ export type Database = {updatedBy?: string | null}Update: {+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -9862,6 +9826,13 @@ export type Database = {updatedBy?: string | null}Relationships: [+ {+ foreignKeyName: "quoteMaterial_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "company"+ referencedColumns: ["id"]+ },{foreignKeyName: "quoteMaterial_createdBy_fkey"columns: ["createdBy"]@@ -9892,24 +9863,17 @@ export type Database = {},{foreignKeyName: "quoteMaterial_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "quoteMaterial_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteMaterial_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteMaterial_quoteId_fkey"@@ -9953,6 +9917,13 @@ export type Database = {referencedRelation: "quoteOperation"referencedColumns: ["id"]},+ {+ foreignKeyName: "quoteMaterial_unitOfMeasureCode_fkey"+ columns: ["unitOfMeasureCode", "companyId"]+ isOneToOne: false+ referencedRelation: "unitOfMeasure"+ referencedColumns: ["code", "companyId"]+ },{foreignKeyName: "quoteMaterial_updatedBy_fkey"columns: ["updatedBy"]@@ -9985,6 +9956,7 @@ export type Database = {}quoteOperation: {Row: {+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -10005,6 +9977,7 @@ export type Database = {workCellTypeId: string}Insert: {+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -10025,6 +9998,7 @@ export type Database = {workCellTypeId: string}Update: {+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -10045,6 +10019,13 @@ export type Database = {workCellTypeId?: string}Relationships: [+ {+ foreignKeyName: "quoteOperation_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "company"+ referencedColumns: ["id"]+ },{foreignKeyName: "quoteOperation_createdBy_fkey"columns: ["createdBy"]@@ -10500,24 +10481,17 @@ export type Database = {},{foreignKeyName: "receiptLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "receiptLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "receiptLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "receiptLine_receiptId_fkey"@@ -10923,24 +10897,17 @@ export type Database = {},{foreignKeyName: "requestForQuoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "requestForQuoteLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "requestForQuoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "requestForQuoteLine_requestForQuoteId_fkey"@@ -11739,24 +11706,17 @@ export type Database = {},{foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_salesOrderId_fkey"@@ -11774,17 +11734,17 @@ export type Database = {},{foreignKeyName: "salesOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_shelfId_fkey"@@ -12678,17 +12638,17 @@ export type Database = {},{foreignKeyName: "serviceSupplier_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "serviceSupplier_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "serviceSupplier_supplierId_fkey"@@ -16698,24 +16658,17 @@ export type Database = {},{foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_purchaseOrderId_fkey"@@ -16747,17 +16700,17 @@ export type Database = {},{foreignKeyName: "purchaseOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "purchaseOrderLine_shelfId_fkey"@@ -17141,24 +17094,17 @@ export type Database = {},{foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]- },- {- foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "quoteLine_quoteId_fkey"@@ -17844,24 +17790,17 @@ export type Database = {},{foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "part"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]- isOneToOne: false- referencedRelation: "partQuantities"- referencedColumns: ["partId"]- },- {- foreignKeyName: "salesOrderLine_partId_fkey"- columns: ["partId"]+ columns: ["partId", "companyId"]isOneToOne: falsereferencedRelation: "parts"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_salesOrderId_fkey"@@ -17879,17 +17818,17 @@ export type Database = {},{foreignKeyName: "salesOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "service"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_serviceId_fkey"- columns: ["serviceId"]+ columns: ["serviceId", "companyId"]isOneToOne: falsereferencedRelation: "services"- referencedColumns: ["id"]+ referencedColumns: ["id", "companyId"]},{foreignKeyName: "salesOrderLine_shelfId_fkey"diff --git a/packages/database/supabase/migrations/20230330024716_parts.sql b/packages/database/supabase/migrations/20230330024716_parts.sqlindex f0bbfacc95..cc8fc8b130 100644--- a/packages/database/supabase/migrations/20230330024716_parts.sql+++ b/packages/database/supabase/migrations/20230330024716_parts.sql@@ -160,7 +160,7 @@ CREATE TABLE "part" ("updatedAt" TIMESTAMP WITH TIME ZONE,"customFields" JSONB,- CONSTRAINT "part_pkey" PRIMARY KEY ("id"),+ CONSTRAINT "part_pkey" PRIMARY KEY ("id", "companyId"),CONSTRAINT "part_unitOfMeasureCode_fkey" FOREIGN KEY ("unitOfMeasureCode", "companyId") REFERENCES "unitOfMeasure"("code", "companyId") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "part_partGroupId_fkey" FOREIGN KEY ("partGroupId") REFERENCES "partGroup"("id") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "part_approvedBy_fkey" FOREIGN KEY ("approvedBy") REFERENCES "user"("id"),@@ -286,7 +286,8 @@ CREATE TABLE "partCost" ("updatedAt" TIMESTAMP WITH TIME ZONE,"customFields" JSONB,- CONSTRAINT "partCost_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part"("id") ON DELETE CASCADE ON UPDATE CASCADE,++ CONSTRAINT "partCost_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part"("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "partCost_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "partGroup_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),CONSTRAINT "partGroup_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id")@@ -325,7 +326,7 @@ CREATE TABLE "partUnitSalePrice" ("updatedAt" TIMESTAMP WITH TIME ZONE,"customFields" JSONB,- CONSTRAINT "partUnitSalePrice_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part"("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "partUnitSalePrice_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part"("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "partUnitSalePrice_currencyCode_fkey" FOREIGN KEY ("currencyCode", "companyId") REFERENCES "currency"("code", "companyId") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "partUnitSalePrice_salesUnitOfMeasureId_fkey" FOREIGN KEY ("salesUnitOfMeasureCode", "companyId") REFERENCES "unitOfMeasure"("code", "companyId") ON DELETE SET NULL,CONSTRAINT "partUnitSalePrice_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,@@ -368,8 +369,8 @@ CREATE TABLE "partSupplier" ("updatedAt" TIMESTAMP WITH TIME ZONE,"customFields" JSONB,- CONSTRAINT "partSupplier_id_pkey" PRIMARY KEY ("id"),- CONSTRAINT "partSupplier_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part"("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "partSupplier_id_pkey" PRIMARY KEY ("id", "companyId"),+ CONSTRAINT "partSupplier_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part"("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "partSupplier_supplierId_fkey" FOREIGN KEY ("supplierId") REFERENCES "supplier"("id") ON DELETE CASCADE,CONSTRAINT "partSupplier_part_supplier_unique" UNIQUE ("partId", "supplierId", "companyId"),CONSTRAINT "partSupplier_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,@@ -454,7 +455,7 @@ CREATE TABLE "partReplenishment" ("updatedAt" TIMESTAMP WITH TIME ZONE,"customFields" JSONB,- CONSTRAINT "partReplenishment_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part"("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "partReplenishment_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part"("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "partReplenishment_preferredSupplierId_fkey" FOREIGN KEY ("preferredSupplierId") REFERENCES "supplier"("id") ON DELETE SET NULL,CONSTRAINT "partReplenishment_purchaseUnitOfMeasureCode_fkey" FOREIGN KEY ("purchasingUnitOfMeasureCode", "companyId") REFERENCES "unitOfMeasure"("code", "companyId") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "partReplenishment_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,@@ -706,7 +707,7 @@ CREATE TABLE "partPlanning" (CONSTRAINT "partPlanning_partId_locationId_key" UNIQUE ("partId", "locationId"),- CONSTRAINT "partPlanning_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part"("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "partPlanning_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part"("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "partPlanning_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "location"("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "partPlanning_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "partPlanning_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),@@ -751,7 +752,7 @@ CREATE TABLE "partInventory" ("customFields" JSONB,CONSTRAINT "partInventory_partId_locationId_key" UNIQUE ("partId", "locationId"),- CONSTRAINT "partInventory_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part"("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "partInventory_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part"("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "partInventory_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "location"("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "partInventory_shelfId_fkey" FOREIGN KEY ("defaultShelfId", "locationId") REFERENCES "shelf"("id", "locationId") ON DELETE SET NULL,CONSTRAINT "partInventory_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,diff --git a/packages/database/supabase/migrations/20230412120726_services.sql b/packages/database/supabase/migrations/20230412120726_services.sqlindex d78c444867..9fdff02bcd 100644--- a/packages/database/supabase/migrations/20230412120726_services.sql+++ b/packages/database/supabase/migrations/20230412120726_services.sql@@ -23,7 +23,7 @@ CREATE TABLE "service" ("updatedBy" TEXT,"updatedAt" TIMESTAMP WITH TIME ZONE,- CONSTRAINT "service_pkey" PRIMARY KEY ("id"),+ CONSTRAINT "service_pkey" PRIMARY KEY ("id", "companyId"),CONSTRAINT "service_partGroupId_fkey" FOREIGN KEY ("partGroupId") REFERENCES "partGroup"("id") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "service_assignee_fkey" FOREIGN KEY ("assignee") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "service_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id"),@@ -79,7 +79,7 @@ CREATE TABLE "serviceSupplier" ("customFields" JSONB,CONSTRAINT "serviceSupplier_id_pkey" PRIMARY KEY ("id"),- CONSTRAINT "serviceSupplier_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "service"("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "serviceSupplier_serviceId_fkey" FOREIGN KEY ("serviceId", "companyId") REFERENCES "service"("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "serviceSupplier_supplierId_fkey" FOREIGN KEY ("supplierId") REFERENCES "supplier"("id") ON DELETE CASCADE,CONSTRAINT "serviceSupplier_service_supplier_unique" UNIQUE ("serviceId", "supplierId"),CONSTRAINT "serviceSupplier_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id"),diff --git a/packages/database/supabase/migrations/20230510035345_purchasing.sql b/packages/database/supabase/migrations/20230510035345_purchasing.sqlindex 5126a8e5f3..44a8140f3b 100644--- a/packages/database/supabase/migrations/20230510035345_purchasing.sql+++ b/packages/database/supabase/migrations/20230510035345_purchasing.sql@@ -351,8 +351,8 @@ CREATE TABLE "purchaseOrderLine" (CONSTRAINT "purchaseOrderLine_pkey" PRIMARY KEY ("id"),CONSTRAINT "purchaseOrderLine_purchaseOrderId_fkey" FOREIGN KEY ("purchaseOrderId") REFERENCES "purchaseOrder" ("id") ON DELETE CASCADE,- CONSTRAINT "purchaseOrderLine_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part" ("id") ON DELETE CASCADE ON UPDATE CASCADE,- CONSTRAINT "purchaseOrderLine_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "service" ("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "purchaseOrderLine_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part" ("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "purchaseOrderLine_serviceId_fkey" FOREIGN KEY ("serviceId", "companyId") REFERENCES "service" ("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "purchaseOrderLine_accountNumber_fkey" FOREIGN KEY ("accountNumber", "companyId") REFERENCES "account" ("number", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,-- TODO: Add assetId foreign keyCONSTRAINT "purchaseOrderLine_shelfId_fkey" FOREIGN KEY ("shelfId", "locationId") REFERENCES "shelf" ("id", "locationId") ON DELETE CASCADE,diff --git a/packages/database/supabase/migrations/20230705033432_ledgers.sql b/packages/database/supabase/migrations/20230705033432_ledgers.sqlindex 40e74a2328..c083ae1b30 100644--- a/packages/database/supabase/migrations/20230705033432_ledgers.sql+++ b/packages/database/supabase/migrations/20230705033432_ledgers.sql@@ -235,7 +235,7 @@ CREATE TABLE "partLedger" ("createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),CONSTRAINT "partLedger_pkey" PRIMARY KEY ("id"),- CONSTRAINT "partLedger_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part"("id") ON UPDATE CASCADE ON DELETE CASCADE,+ CONSTRAINT "partLedger_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part"("id", "companyId") ON UPDATE CASCADE ON DELETE CASCADE,CONSTRAINT "partLedger_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "location"("id") ON UPDATE CASCADE ON DELETE SET NULL,CONSTRAINT "partLedger_shelfId_fkey" FOREIGN KEY ("shelfId", "locationId") REFERENCES "shelf"("id", "locationId") ON UPDATE CASCADE ON DELETE SET NULL,CONSTRAINT "partLeger_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company" ("id") ON DELETE CASCADE ON UPDATE CASCADEdiff --git a/packages/database/supabase/migrations/20230728025201_receipts.sql b/packages/database/supabase/migrations/20230728025201_receipts.sqlindex 16541bcd4e..c9d5fdb1ef 100644--- a/packages/database/supabase/migrations/20230728025201_receipts.sql+++ b/packages/database/supabase/migrations/20230728025201_receipts.sql@@ -107,7 +107,7 @@ CREATE TABLE "receiptLine" (CONSTRAINT "receiptLine_pkey" PRIMARY KEY ("id"),CONSTRAINT "receiptLine_receiptId_fkey" FOREIGN KEY ("receiptId") REFERENCES "receipt" ("id") ON DELETE CASCADE ON UPDATE CASCADE,- CONSTRAINT "receiptLine_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part" ("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "receiptLine_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part" ("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "receiptLine_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "location" ("id") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "receiptLine_shelfId_fkey" FOREIGN KEY ("shelfId", "locationId") REFERENCES "shelf" ("id", "locationId") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "receiptLine_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,diff --git a/packages/database/supabase/migrations/20230924004608_accounts-payable.sql b/packages/database/supabase/migrations/20230924004608_accounts-payable.sqlindex 306113f0fb..e560180720 100644--- a/packages/database/supabase/migrations/20230924004608_accounts-payable.sql+++ b/packages/database/supabase/migrations/20230924004608_accounts-payable.sql@@ -190,8 +190,8 @@ CREATE TABLE "purchaseInvoiceLine" (CONSTRAINT "purchaseInvoiceLines_invoiceId_fkey" FOREIGN KEY ("invoiceId") REFERENCES "purchaseInvoice" ("id") ON UPDATE CASCADE ON DELETE CASCADE,CONSTRAINT "purchaseInvoiceLines_purchaseOrderId_fkey" FOREIGN KEY ("purchaseOrderId") REFERENCES "purchaseOrder" ("id") ON UPDATE CASCADE ON DELETE RESTRICT,CONSTRAINT "purchaseInvoiceLines_purchaseOrderLineId_fkey" FOREIGN KEY ("purchaseOrderLineId") REFERENCES "purchaseOrderLine" ("id") ON UPDATE CASCADE ON DELETE RESTRICT,- CONSTRAINT "purchaseInvoiceLines_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part" ("id") ON UPDATE CASCADE ON DELETE RESTRICT,- CONSTRAINT "purchaseInvoiceLines_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "service" ("id") ON UPDATE CASCADE ON DELETE RESTRICT,+ CONSTRAINT "purchaseInvoiceLines_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part" ("id", "companyId") ON UPDATE CASCADE ON DELETE RESTRICT,+ CONSTRAINT "purchaseInvoiceLines_serviceId_fkey" FOREIGN KEY ("serviceId", "companyId") REFERENCES "service" ("id", "companyId") ON UPDATE CASCADE ON DELETE RESTRICT,CONSTRAINT "purchaseInvoiceLines_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "location" ("id") ON UPDATE CASCADE ON DELETE RESTRICT,CONSTRAINT "purchaseInvoiceLines_shelfId_fkey" FOREIGN KEY ("shelfId", "locationId") REFERENCES "shelf" ("id", "locationId") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "purchaseInvoiceLines_accountNumber_fkey" FOREIGN KEY ("accountNumber", "companyId") REFERENCES "account" ("number", "companyId") ON UPDATE CASCADE ON DELETE RESTRICT,diff --git a/packages/database/supabase/migrations/20240204025905_rfq.sql b/packages/database/supabase/migrations/20240204025905_rfq.sqlindex 81c9345a41..3147df0b0b 100644--- a/packages/database/supabase/migrations/20240204025905_rfq.sql+++ b/packages/database/supabase/migrations/20240204025905_rfq.sql@@ -48,7 +48,7 @@ CREATE TABLE "requestForQuoteLine" (CONSTRAINT "requestForQuoteLine_pkey" PRIMARY KEY ("id"),CONSTRAINT "requestForQuoteLine_requestForQuoteId_fkey" FOREIGN KEY ("requestForQuoteId") REFERENCES "requestForQuote"("id") ON DELETE CASCADE ON UPDATE CASCADE,- CONSTRAINT "requestForQuoteLine_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part"("id") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "requestForQuoteLine_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part"("id", "companyId") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "requestForQuoteLine_unitOfMeasureCode_fkey" FOREIGN KEY ("unitOfMeasureCode", "companyId") REFERENCES "unitOfMeasure"("code", "companyId") ON UPDATE CASCADE ON DELETE SET NULL,CONSTRAINT "requestForQuoteLine_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "location"("id") ON UPDATE CASCADE ON DELETE SET NULL,CONSTRAINT "requestForQuoteLine_shelfId_fkey" FOREIGN KEY ("shelfId", "locationId") REFERENCES "shelf" ("id", "locationId") ON DELETE CASCADE,diff --git a/packages/database/supabase/migrations/20240206224405_quotes.sql b/packages/database/supabase/migrations/20240206224405_quotes.sqlindex d6d1f0e896..3c1cbc4f73 100644--- a/packages/database/supabase/migrations/20240206224405_quotes.sql+++ b/packages/database/supabase/migrations/20240206224405_quotes.sql@@ -78,7 +78,7 @@ CREATE TABLE "quoteLine" (CONSTRAINT "quoteLine_pkey" PRIMARY KEY ("id"),CONSTRAINT "quoteLine_quoteId_fkey" FOREIGN KEY ("quoteId") REFERENCES "quote" ("id") ON DELETE CASCADE ON UPDATE CASCADE,- CONSTRAINT "quoteLine_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "quoteLine_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part" ("id", "companyId") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "quoteLine_unitOfMeasureCode_fkey" FOREIGN KEY ("unitOfMeasureCode", "companyId") REFERENCES "unitOfMeasure" ("code", "companyId") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "quoteLine_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "quoteLine_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,@@ -96,6 +96,7 @@ CREATE TABLE "quoteAssembly" ("description" TEXT,"unitOfMeasureCode" TEXT,"quantityPerParent" NUMERIC(10, 2) NOT NULL DEFAULT 0,+ "companyId" INTEGER NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),"createdBy" TEXT NOT NULL,"updatedAt" TIMESTAMP WITH TIME ZONE,@@ -106,6 +107,9 @@ CREATE TABLE "quoteAssembly" (CONSTRAINT "quoteAssembly_quoteId_fkey" FOREIGN KEY ("quoteId") REFERENCES "quote" ("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "quoteAssembly_quoteLineId_fkey" FOREIGN KEY ("quoteLineId") REFERENCES "quoteLine" ("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "quoteAssembly_parentAssemblyId_fkey" FOREIGN KEY ("parentAssemblyId") REFERENCES "quoteAssembly" ("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "quoteAssembly_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part" ("id", "companyId") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "quoteAssembly_unitOfMeasureCode_fkey" FOREIGN KEY ("unitOfMeasureCode", "companyId") REFERENCES "unitOfMeasure" ("code", "companyId") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "quoteAssembly_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "quoteAssembly_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "quoteAssembly_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE);@@ -128,6 +132,7 @@ CREATE TABLE "quoteOperation" ("quotingRate" NUMERIC(10,4) NOT NULL DEFAULT 0,"laborRate" NUMERIC(10,4) NOT NULL DEFAULT 0,"overheadRate" NUMERIC(10,4) NOT NULL DEFAULT 0,+ "companyId" INTEGER NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),"createdBy" TEXT NOT NULL,"updatedAt" TIMESTAMP WITH TIME ZONE,@@ -140,6 +145,7 @@ CREATE TABLE "quoteOperation" (CONSTRAINT "quoteOperation_quoteAssemblyId_fkey" FOREIGN KEY ("quoteAssemblyId") REFERENCES "quoteAssembly" ("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "quoteOperation_workCellTypeId_fkey" FOREIGN KEY ("workCellTypeId") REFERENCES "workCellType" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "quoteOperation_equipmentTypeId_fkey" FOREIGN KEY ("equipmentTypeId") REFERENCES "equipmentType" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "quoteOperation_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "quoteOperation_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "quoteOperation_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE);@@ -158,6 +164,7 @@ CREATE TABLE "quoteMaterial" ("quantity" NUMERIC(10, 2) NOT NULL DEFAULT 0,"unitOfMeasureCode" TEXT,"unitCost" NUMERIC(10, 2) NOT NULL DEFAULT 0,+ "companyId" INTEGER NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),"createdBy" TEXT NOT NULL,"updatedAt" TIMESTAMP WITH TIME ZONE,@@ -168,7 +175,9 @@ CREATE TABLE "quoteMaterial" (CONSTRAINT "quoteMaterial_quoteId_fkey" FOREIGN KEY ("quoteId") REFERENCES "quote" ("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "quoteMaterial_quoteLineId_fkey" FOREIGN KEY ("quoteLineId") REFERENCES "quoteLine" ("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "quoteMaterial_quoteOperationId_fkey" FOREIGN KEY ("quoteOperationId") REFERENCES "quoteOperation" ("id") ON DELETE CASCADE ON UPDATE CASCADE,- CONSTRAINT "quoteMaterial_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "quoteMaterial_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part" ("id", "companyId") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "quoteMaterial_unitOfMeasureCode_fkey" FOREIGN KEY ("unitOfMeasureCode", "companyId") REFERENCES "unitOfMeasure" ("code", "companyId") ON DELETE RESTRICT ON UPDATE CASCADE,+ CONSTRAINT "quoteMaterial_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "quoteMaterial_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "quoteMaterial_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE);diff --git a/packages/database/supabase/migrations/20240412224648_sales-orders.sql b/packages/database/supabase/migrations/20240412224648_sales-orders.sqlindex 80a153eb95..4f1d09be24 100644--- a/packages/database/supabase/migrations/20240412224648_sales-orders.sql+++ b/packages/database/supabase/migrations/20240412224648_sales-orders.sql@@ -128,8 +128,8 @@ CREATE TABLE "salesOrderLine" (CONSTRAINT "salesOrderLine_pkey" PRIMARY KEY ("id"),CONSTRAINT "salesOrderLine_salesOrderId_fkey" FOREIGN KEY ("salesOrderId") REFERENCES "salesOrder" ("id") ON DELETE CASCADE,- CONSTRAINT "salesOrderLine_partId_fkey" FOREIGN KEY ("partId") REFERENCES "part" ("id") ON DELETE CASCADE ON UPDATE CASCADE,- CONSTRAINT "salesOrderLine_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "service" ("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "salesOrderLine_partId_fkey" FOREIGN KEY ("partId", "companyId") REFERENCES "part" ("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "salesOrderLine_serviceId_fkey" FOREIGN KEY ("serviceId", "companyId") REFERENCES "service" ("id", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "salesOrderLine_accountNumber_fkey" FOREIGN KEY ("accountNumber", "companyId") REFERENCES "account" ("number", "companyId") ON DELETE CASCADE ON UPDATE CASCADE,-- TODO: Add assetId foreign keyCONSTRAINT "salesOrderLine_shelfId_fkey" FOREIGN KEY ("shelfId", "locationId") REFERENCES "shelf" ("id", "locationId") ON DELETE CASCADE,