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 - purchasing
Brad Barbin4feec9b73e24
diff --git a/apps/carbon/app/modules/purchasing/purchasing.service.ts b/apps/carbon/app/modules/purchasing/purchasing.service.tsindex 2ef38a1114..d6e885a416 100644--- a/apps/carbon/app/modules/purchasing/purchasing.service.ts+++ b/apps/carbon/app/modules/purchasing/purchasing.service.ts@@ -142,13 +142,17 @@ export async function getPurchaseOrder(export async function getPurchaseOrders(client: SupabaseClient<Database>,+ companyId: number,args: GenericQueryFilters & {search: string | null;status: string | null;supplierId: string | null;}) {- let query = client.from("purchaseOrders").select("*", { count: "exact" });+ let query = client+ .from("purchaseOrders")+ .select("*", { count: "exact" })+ .eq("companyId", companyId);if (args.search) {query = query.or(@@ -224,18 +228,27 @@ export async function getPurchaseOrderLine(}export async function getPurchaseOrderSuppliers(- client: SupabaseClient<Database>+ client: SupabaseClient<Database>,+ companyId: number) {- return client.from("purchaseOrderSuppliers").select("id, name");+ return client+ .from("purchaseOrderSuppliers")+ .select("id, name")+ .eq("companyId", companyId)+ .order("name");}export async function getRequestsForQuotes(client: SupabaseClient<Database>,+ companyId: number,args: GenericQueryFilters & {search: string | null;}) {- let query = client.from("requestForQuotes").select("*", { count: "exact" });+ let query = client+ .from("requestForQuotes")+ .select("*", { count: "exact" })+ .eq("companyId", companyId);if (args.search) {query = query.or(@@ -331,15 +344,19 @@ export async function getSupplierShipping(export async function getSuppliers(client: SupabaseClient<Database>,+ companyId: number,args: GenericQueryFilters & {search: string | null;type: string | null;status: string | null;}) {- let query = client.from("suppliers").select("*", {- count: "exact",- });+ let query = client+ .from("suppliers")+ .select("*", {+ count: "exact",+ })+ .eq("companyId", companyId);if (args.search) {query = query.ilike("name", `%${args.search}%`);@@ -359,8 +376,15 @@ export async function getSuppliers(return query;}-export async function getSuppliersList(client: SupabaseClient<Database>) {- return client.from("supplier").select("id, name").order("name");+export async function getSuppliersList(+ client: SupabaseClient<Database>,+ companyId: number+) {+ return client+ .from("supplier")+ .select("id, name")+ .eq("companyId", companyId)+ .order("name");}export async function getSupplierStatus(@@ -376,9 +400,13 @@ export async function getSupplierStatus(export async function getSupplierStatuses(client: SupabaseClient<Database>,+ companyId: number,args?: GenericQueryFilters & { search: string | null }) {- let query = client.from("supplierStatus").select("*", { count: "exact" });+ let query = client+ .from("supplierStatus")+ .select("*", { count: "exact" })+ .eq("companyId", companyId);if (args?.search) {query = query.ilike("name", `%${args.search}%`);@@ -394,9 +422,14 @@ export async function getSupplierStatuses(}export async function getSupplierStatusesList(- client: SupabaseClient<Database>+ client: SupabaseClient<Database>,+ companyId: number) {- return client.from("supplierStatus").select("id, name").order("name");+ return client+ .from("supplierStatus")+ .select("id, name")+ .eq("companyId", companyId)+ .order("name");}export async function getSupplierType(@@ -412,9 +445,13 @@ export async function getSupplierType(export async function getSupplierTypes(client: SupabaseClient<Database>,+ companyId: number,args?: GenericQueryFilters & { search: string | null }) {- let query = client.from("supplierType").select("*", { count: "exact" });+ let query = client+ .from("supplierType")+ .select("*", { count: "exact" })+ .eq("companyId", companyId);if (args?.search) {query = query.ilike("name", `%${args.search}%`);@@ -429,13 +466,21 @@ export async function getSupplierTypes(return query;}-export async function getSupplierTypesList(client: SupabaseClient<Database>) {- return client.from("supplierType").select("id, name").order("name");+export async function getSupplierTypesList(+ client: SupabaseClient<Database>,+ companyId: number+) {+ return client+ .from("supplierType")+ .select("id, name")+ .eq("companyId", companyId)+ .order("name");}export async function insertSupplier(client: SupabaseClient<Database>,supplier: Omit<z.infer<typeof supplierValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;}@@ -486,20 +531,23 @@ export async function insertSupplierLocation(client: SupabaseClient<Database>,supplierLocation: {supplierId: string;+ companyId: number;address: {addressLine1?: string;addressLine2?: string;city?: string;state?: string;- // countryId: string;postalCode?: string;+ // countryId: string;};customFields?: Json;}) {const insertAddress = await client.from("address")- .insert([supplierLocation.address])+ .insert([+ { ...supplierLocation.address, companyId: supplierLocation.companyId },+ ]).select("id").single();if (insertAddress.error) {@@ -587,6 +635,7 @@ export async function upsertSupplier(client: SupabaseClient<Database>,supplier:| (Omit<z.infer<typeof supplierValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -883,6 +932,7 @@ export async function upsertRequestForQuote("id" | "requestForQuoteId"> & {requestForQuoteId: string;+ companyId: number;createdBy: string;customFields?: Json;})@@ -916,6 +966,7 @@ export async function upsertSupplierStatus(client: SupabaseClient<Database>,supplierStatus:| (Omit<z.infer<typeof supplierStatusValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})@@ -943,6 +994,7 @@ export async function upsertSupplierType(client: SupabaseClient<Database>,supplierType:| (Omit<z.infer<typeof supplierTypeValidator>, "id"> & {+ companyId: number;createdBy: string;customFields?: Json;})diff --git a/apps/carbon/app/routes/api+/purchasing.supplier-statuses.ts b/apps/carbon/app/routes/api+/purchasing.supplier-statuses.tsindex 2e823b088b..798c58ef3e 100644--- a/apps/carbon/app/routes/api+/purchasing.supplier-statuses.ts+++ b/apps/carbon/app/routes/api+/purchasing.supplier-statuses.ts@@ -4,9 +4,9 @@ import { getSupplierStatusesList } from "~/modules/purchasing";import { requirePermissions } from "~/services/auth/auth.server";export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "purchasing",});- return json(await getSupplierStatusesList(authorized.client));+ return json(await getSupplierStatusesList(client, companyId));}diff --git a/apps/carbon/app/routes/api+/purchasing.suppliers.ts b/apps/carbon/app/routes/api+/purchasing.suppliers.tsindex c80eeb44a9..b478db3a58 100644--- a/apps/carbon/app/routes/api+/purchasing.suppliers.ts+++ b/apps/carbon/app/routes/api+/purchasing.suppliers.ts@@ -4,9 +4,9 @@ import { getSuppliersList } from "~/modules/purchasing";import { requirePermissions } from "~/services/auth/auth.server";export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "purchasing",});- return json(await getSuppliersList(authorized.client));+ return json(await getSuppliersList(client, companyId));}diff --git a/apps/carbon/app/routes/x+/accounting+/groups.purchasing.tsx b/apps/carbon/app/routes/x+/accounting+/groups.purchasing.tsxindex f3e306c380..b9087feb13 100644--- a/apps/carbon/app/routes/x+/accounting+/groups.purchasing.tsx+++ b/apps/carbon/app/routes/x+/accounting+/groups.purchasing.tsx@@ -40,7 +40,7 @@ export async function loader({ request }: LoaderFunctionArgs) {filters,}),getPartGroupsList(client, companyId),- getSupplierTypesList(client),+ getSupplierTypesList(client, companyId),]);if (purchasingGroups.error) {throw redirect(diff --git a/apps/carbon/app/routes/x+/purchasing+/orders.tsx b/apps/carbon/app/routes/x+/purchasing+/orders.tsxindex 9ed35f9c8b..f06a462ff3 100644--- a/apps/carbon/app/routes/x+/purchasing+/orders.tsx+++ b/apps/carbon/app/routes/x+/purchasing+/orders.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: "purchasing",});@@ -30,7 +30,7 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [purchasOrders] = await Promise.all([- getPurchaseOrders(client, {+ getPurchaseOrders(client, companyId, {search,status,supplierId,diff --git a/apps/carbon/app/routes/x+/purchasing+/rfqs.tsx b/apps/carbon/app/routes/x+/purchasing+/rfqs.tsxindex da31cce965..81ae57d078 100644--- a/apps/carbon/app/routes/x+/purchasing+/rfqs.tsx+++ b/apps/carbon/app/routes/x+/purchasing+/rfqs.tsx@@ -19,7 +19,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "purchasing",});@@ -31,7 +31,7 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [requestForQuotes] = await Promise.all([- getRequestsForQuotes(client, {+ getRequestsForQuotes(client, companyId, {search,limit,offset,diff --git a/apps/carbon/app/routes/x+/purchasing+/supplier-statuses.new.tsx b/apps/carbon/app/routes/x+/purchasing+/supplier-statuses.new.tsxindex 9926be066b..71a2264285 100644--- a/apps/carbon/app/routes/x+/purchasing+/supplier-statuses.new.tsx+++ b/apps/carbon/app/routes/x+/purchasing+/supplier-statuses.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: "purchasing",});@@ -43,6 +43,7 @@ export async function action({ request }: ActionFunctionArgs) {const insertSupplierStatus = await upsertSupplierStatus(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/purchasing+/supplier-types.new.tsx b/apps/carbon/app/routes/x+/purchasing+/supplier-types.new.tsxindex 07e319b8da..cf9ce47990 100644--- a/apps/carbon/app/routes/x+/purchasing+/supplier-types.new.tsx+++ b/apps/carbon/app/routes/x+/purchasing+/supplier-types.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: "purchasing",});@@ -41,6 +41,7 @@ export async function action({ request }: ActionFunctionArgs) {const insertSupplierType = await upsertSupplierType(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/purchasing+/supplier-types.tsx b/apps/carbon/app/routes/x+/purchasing+/supplier-types.tsxindex 177ac50ad6..dcb1fb59c2 100644--- a/apps/carbon/app/routes/x+/purchasing+/supplier-types.tsx+++ b/apps/carbon/app/routes/x+/purchasing+/supplier-types.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: "purchasing",role: "employee",});@@ -24,7 +24,9 @@ export async function loader({ request }: LoaderFunctionArgs) {const search = searchParams.get("search");const { limit, offset, sorts } = getGenericQueryFilters(searchParams);- return json(await getSupplierTypes(client, { search, limit, offset, sorts }));+ return json(+ await getSupplierTypes(client, companyId, { search, limit, offset, sorts })+ );}export default function SupplierTypesRoute() {diff --git a/apps/carbon/app/routes/x+/purchasing+/suppliers.tsx b/apps/carbon/app/routes/x+/purchasing+/suppliers.tsxindex d57ba89c1c..08ed0fc281 100644--- a/apps/carbon/app/routes/x+/purchasing+/suppliers.tsx+++ b/apps/carbon/app/routes/x+/purchasing+/suppliers.tsx@@ -21,7 +21,7 @@ export const handle: Handle = {};export async function loader({ request }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {view: "purchasing",});@@ -35,7 +35,7 @@ export async function loader({ request }: LoaderFunctionArgs) {getGenericQueryFilters(searchParams);const [suppliers, supplierTypes, supplierStatuses] = await Promise.all([- getSuppliers(client, {+ getSuppliers(client, companyId, {search,type,status,@@ -44,8 +44,8 @@ export async function loader({ request }: LoaderFunctionArgs) {sorts,filters,}),- getSupplierTypes(client),- getSupplierStatuses(client),+ getSupplierTypes(client, companyId),+ getSupplierStatuses(client, companyId),]);if (suppliers.error) {diff --git a/apps/carbon/app/routes/x+/rfq+/new.tsx b/apps/carbon/app/routes/x+/rfq+/new.tsxindex e3b761feeb..0905265aa7 100644--- a/apps/carbon/app/routes/x+/rfq+/new.tsx+++ b/apps/carbon/app/routes/x+/rfq+/new.tsx@@ -16,7 +16,7 @@ import { error } from "~/utils/result";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "purchasing",});@@ -43,6 +43,7 @@ export async function action({ request }: ActionFunctionArgs) {const createRequestForQuote = await upsertRequestForQuote(client, {...validation.data,requestForQuoteId: nextSequence.data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsxindex e7cc6dce45..2af8689d77 100644--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsx+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsx@@ -16,7 +16,7 @@ import { error, success } from "~/utils/result";export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {create: "purchasing",});@@ -38,6 +38,7 @@ export async function action({ request, params }: ActionFunctionArgs) {const createSupplierLocation = await insertSupplierLocation(client, {supplierId,+ companyId,address,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/supplier+/_layout.tsx b/apps/carbon/app/routes/x+/supplier+/_layout.tsxindex 2cd7cd78d5..3fd109e607 100644--- a/apps/carbon/app/routes/x+/supplier+/_layout.tsx+++ b/apps/carbon/app/routes/x+/supplier+/_layout.tsx@@ -34,8 +34,8 @@ export async function loader({ request }: LoaderFunctionArgs) {shippingMethods,shippingTerms,] = await Promise.all([- getSupplierTypes(client),- getSupplierStatuses(client),+ getSupplierTypes(client, companyId),+ getSupplierStatuses(client, companyId),getPaymentTermsList(client, companyId),getShippingMethodsList(client, companyId),getShippingTermsList(client, companyId),diff --git a/apps/carbon/app/routes/x+/supplier+/new.tsx b/apps/carbon/app/routes/x+/supplier+/new.tsxindex eecbb5c55b..4395c20414 100644--- a/apps/carbon/app/routes/x+/supplier+/new.tsx+++ b/apps/carbon/app/routes/x+/supplier+/new.tsx@@ -15,7 +15,7 @@ import { error } from "~/utils/result";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {create: "purchasing",});@@ -32,6 +32,7 @@ export async function action({ request }: ActionFunctionArgs) {const createSupplier = await upsertSupplier(client, {...data,+ companyId,createdBy: userId,customFields: setCustomFields(formData),});diff --git a/apps/carbon/app/routes/x+/users+/suppliers.tsx b/apps/carbon/app/routes/x+/users+/suppliers.tsxindex f4e23e2932..1e7ef4e31f 100644--- a/apps/carbon/app/routes/x+/users+/suppliers.tsx+++ b/apps/carbon/app/routes/x+/users+/suppliers.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: "users",});@@ -36,7 +36,7 @@ export async function loader({ request }: LoaderFunctionArgs) {sorts,filters,}),- getSupplierTypes(client),+ getSupplierTypes(client, companyId),]);if (suppliers.error) {throw redirect(diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 30a85c1416..870cdbf981 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -1330,7 +1330,7 @@ export type Database = {addressLine1: string | nulladdressLine2: string | nullcity: string | null- companyId: number | null+ companyId: numbercountryCode: number | nullfax: string | nullid: string@@ -1342,7 +1342,7 @@ export type Database = {addressLine1?: string | nulladdressLine2?: string | nullcity?: string | null- companyId?: number | null+ companyId: numbercountryCode?: number | nullfax?: string | nullid?: string@@ -1354,7 +1354,7 @@ export type Database = {addressLine1?: string | nulladdressLine2?: string | nullcity?: string | null- companyId?: number | null+ companyId?: numbercountryCode?: number | nullfax?: string | nullid?: string@@ -1501,7 +1501,7 @@ export type Database = {addressLine2: string | nullbirthday: string | nullcity: string | null- companyId: number | null+ companyId: numbercountryCode: number | nullemail: stringfax: string | null@@ -1522,7 +1522,7 @@ export type Database = {addressLine2?: string | nullbirthday?: string | nullcity?: string | null- companyId?: number | null+ companyId: numbercountryCode?: number | nullemail: stringfax?: string | null@@ -1543,7 +1543,7 @@ export type Database = {addressLine2?: string | nullbirthday?: string | nullcity?: string | null- companyId?: number | null+ companyId?: numbercountryCode?: number | nullemail?: stringfax?: string | null@@ -2108,7 +2108,7 @@ export type Database = {Row: {accountManagerId: string | nullassignee: string | null- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: string | nullcustomerStatusId: string | null@@ -2124,7 +2124,7 @@ export type Database = {Insert: {accountManagerId?: string | nullassignee?: string | null- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy?: string | nullcustomerStatusId?: string | null@@ -2140,7 +2140,7 @@ export type Database = {Update: {accountManagerId?: string | nullassignee?: string | null- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: string | nullcustomerStatusId?: string | null@@ -2791,7 +2791,7 @@ export type Database = {}customerStatus: {Row: {- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -2801,7 +2801,7 @@ export type Database = {updatedBy: string | null}Insert: {- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -2811,7 +2811,7 @@ export type Database = {updatedBy?: string | null}Update: {- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -2888,7 +2888,7 @@ export type Database = {}customerType: {Row: {- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -2899,7 +2899,7 @@ export type Database = {updatedBy: string | null}Insert: {- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -2910,7 +2910,7 @@ export type Database = {updatedBy?: string | null}Update: {- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -12327,7 +12327,7 @@ export type Database = {}search: {Row: {- companyId: number | null+ companyId: numberdescription: string | nullentity: Database["public"]["Enums"]["searchEntity"] | nullfts: unknown | null@@ -12337,7 +12337,7 @@ export type Database = {uuid: string | null}Insert: {- companyId?: number | null+ companyId: numberdescription?: string | nullentity?: Database["public"]["Enums"]["searchEntity"] | nullfts?: unknown | null@@ -12347,7 +12347,7 @@ export type Database = {uuid?: string | null}Update: {- companyId?: number | null+ companyId?: numberdescription?: string | nullentity?: Database["public"]["Enums"]["searchEntity"] | nullfts?: unknown | null@@ -13309,7 +13309,7 @@ export type Database = {Row: {accountManagerId: string | nullassignee: string | null- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: string | nullcustomFields: Json | null@@ -13325,7 +13325,7 @@ export type Database = {Insert: {accountManagerId?: string | nullassignee?: string | null- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy?: string | nullcustomFields?: Json | null@@ -13341,7 +13341,7 @@ export type Database = {Update: {accountManagerId?: string | nullassignee?: string | null- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: string | nullcustomFields?: Json | null@@ -14184,7 +14184,7 @@ export type Database = {}supplierStatus: {Row: {- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -14194,7 +14194,7 @@ export type Database = {updatedBy: string | null}Insert: {- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -14204,7 +14204,7 @@ export type Database = {updatedBy?: string | null}Update: {- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -14281,7 +14281,7 @@ export type Database = {}supplierType: {Row: {- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -14292,7 +14292,7 @@ export type Database = {updatedBy: string | null}Insert: {- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -14303,7 +14303,7 @@ export type Database = {updatedBy?: string | null}Update: {- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | nulldiff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex 30a85c1416..870cdbf981 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -1330,7 +1330,7 @@ export type Database = {addressLine1: string | nulladdressLine2: string | nullcity: string | null- companyId: number | null+ companyId: numbercountryCode: number | nullfax: string | nullid: string@@ -1342,7 +1342,7 @@ export type Database = {addressLine1?: string | nulladdressLine2?: string | nullcity?: string | null- companyId?: number | null+ companyId: numbercountryCode?: number | nullfax?: string | nullid?: string@@ -1354,7 +1354,7 @@ export type Database = {addressLine1?: string | nulladdressLine2?: string | nullcity?: string | null- companyId?: number | null+ companyId?: numbercountryCode?: number | nullfax?: string | nullid?: string@@ -1501,7 +1501,7 @@ export type Database = {addressLine2: string | nullbirthday: string | nullcity: string | null- companyId: number | null+ companyId: numbercountryCode: number | nullemail: stringfax: string | null@@ -1522,7 +1522,7 @@ export type Database = {addressLine2?: string | nullbirthday?: string | nullcity?: string | null- companyId?: number | null+ companyId: numbercountryCode?: number | nullemail: stringfax?: string | null@@ -1543,7 +1543,7 @@ export type Database = {addressLine2?: string | nullbirthday?: string | nullcity?: string | null- companyId?: number | null+ companyId?: numbercountryCode?: number | nullemail?: stringfax?: string | null@@ -2108,7 +2108,7 @@ export type Database = {Row: {accountManagerId: string | nullassignee: string | null- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: string | nullcustomerStatusId: string | null@@ -2124,7 +2124,7 @@ export type Database = {Insert: {accountManagerId?: string | nullassignee?: string | null- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy?: string | nullcustomerStatusId?: string | null@@ -2140,7 +2140,7 @@ export type Database = {Update: {accountManagerId?: string | nullassignee?: string | null- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: string | nullcustomerStatusId?: string | null@@ -2791,7 +2791,7 @@ export type Database = {}customerStatus: {Row: {- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -2801,7 +2801,7 @@ export type Database = {updatedBy: string | null}Insert: {- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -2811,7 +2811,7 @@ export type Database = {updatedBy?: string | null}Update: {- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -2888,7 +2888,7 @@ export type Database = {}customerType: {Row: {- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -2899,7 +2899,7 @@ export type Database = {updatedBy: string | null}Insert: {- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -2910,7 +2910,7 @@ export type Database = {updatedBy?: string | null}Update: {- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -12327,7 +12327,7 @@ export type Database = {}search: {Row: {- companyId: number | null+ companyId: numberdescription: string | nullentity: Database["public"]["Enums"]["searchEntity"] | nullfts: unknown | null@@ -12337,7 +12337,7 @@ export type Database = {uuid: string | null}Insert: {- companyId?: number | null+ companyId: numberdescription?: string | nullentity?: Database["public"]["Enums"]["searchEntity"] | nullfts?: unknown | null@@ -12347,7 +12347,7 @@ export type Database = {uuid?: string | null}Update: {- companyId?: number | null+ companyId?: numberdescription?: string | nullentity?: Database["public"]["Enums"]["searchEntity"] | nullfts?: unknown | null@@ -13309,7 +13309,7 @@ export type Database = {Row: {accountManagerId: string | nullassignee: string | null- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: string | nullcustomFields: Json | null@@ -13325,7 +13325,7 @@ export type Database = {Insert: {accountManagerId?: string | nullassignee?: string | null- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy?: string | nullcustomFields?: Json | null@@ -13341,7 +13341,7 @@ export type Database = {Update: {accountManagerId?: string | nullassignee?: string | null- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: string | nullcustomFields?: Json | null@@ -14184,7 +14184,7 @@ export type Database = {}supplierStatus: {Row: {- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -14194,7 +14194,7 @@ export type Database = {updatedBy: string | null}Insert: {- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -14204,7 +14204,7 @@ export type Database = {updatedBy?: string | null}Update: {- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | null@@ -14281,7 +14281,7 @@ export type Database = {}supplierType: {Row: {- companyId: number | null+ companyId: numbercreatedAt: stringcreatedBy: stringcustomFields: Json | null@@ -14292,7 +14292,7 @@ export type Database = {updatedBy: string | null}Insert: {- companyId?: number | null+ companyId: numbercreatedAt?: stringcreatedBy: stringcustomFields?: Json | null@@ -14303,7 +14303,7 @@ export type Database = {updatedBy?: string | null}Update: {- companyId?: number | null+ companyId?: numbercreatedAt?: stringcreatedBy?: stringcustomFields?: Json | nulldiff --git a/packages/database/supabase/migrations/20230123004612_suppliers-and-customers.sql b/packages/database/supabase/migrations/20230123004612_suppliers-and-customers.sqlindex dc83e9c2c5..0c3af56a75 100644--- a/packages/database/supabase/migrations/20230123004612_suppliers-and-customers.sql+++ b/packages/database/supabase/migrations/20230123004612_suppliers-and-customers.sql@@ -23,7 +23,7 @@ CREATE TABLE "contact" ("countryCode" INTEGER,"birthday" DATE,"notes" TEXT,- "companyId" INTEGER,+ "companyId" INTEGER NOT NULL,CONSTRAINT "contact_pkey" PRIMARY KEY ("id"),CONSTRAINT "contact_countryCode_fkey" FOREIGN KEY ("countryCode") REFERENCES "country"("id") ON DELETE SET NULL ON UPDATE CASCADE,@@ -42,7 +42,7 @@ CREATE TABLE "address" ("countryCode" INTEGER,"phone" TEXT,"fax" TEXT,- "companyId" INTEGER,+ "companyId" INTEGER NOT NULL,CONSTRAINT "address_pkey" PRIMARY KEY ("id"),CONSTRAINT "address_countryCode_fkey" FOREIGN KEY ("countryCode") REFERENCES "country"("id") ON DELETE SET NULL ON UPDATE CASCADE,@@ -54,7 +54,7 @@ CREATE INDEX "address_companyId_idx" ON "address" ("companyId");CREATE TABLE "supplierStatus" ("id" TEXT NOT NULL DEFAULT xid(),"name" TEXT NOT NULL,- "companyId" INTEGER,+ "companyId" INTEGER NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),"createdBy" TEXT NOT NULL,"updatedBy" TEXT,@@ -74,7 +74,7 @@ CREATE TABLE "supplierType" ("id" TEXT NOT NULL DEFAULT uuid_generate_v4(),"name" TEXT NOT NULL,"protected" BOOLEAN NOT NULL DEFAULT false,- "companyId" INTEGER,+ "companyId" INTEGER NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),"createdBy" TEXT NOT NULL,"updatedBy" TEXT,@@ -99,7 +99,7 @@ CREATE TABLE "supplier" ("accountManagerId" TEXT,"logo" TEXT,"assignee" TEXT,- "companyId" INTEGER,+ "companyId" INTEGER NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,"createdBy" TEXT,"updatedAt" TIMESTAMP WITH TIME ZONE,@@ -166,7 +166,7 @@ CREATE INDEX "supplierAccount_companyId_idx" ON "supplierAccount" ("companyId");CREATE TABLE "customerStatus" ("id" TEXT NOT NULL DEFAULT xid(),"name" TEXT NOT NULL,- "companyId" INTEGER,+ "companyId" INTEGER NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),"createdBy" TEXT NOT NULL,"updatedBy" TEXT,@@ -186,7 +186,7 @@ CREATE TABLE "customerType" ("id" TEXT NOT NULL DEFAULT uuid_generate_v4(),"name" TEXT NOT NULL,"protected" BOOLEAN NOT NULL DEFAULT false,- "companyId" INTEGER,+ "companyId" INTEGER NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),"createdBy" TEXT NOT NULL,"updatedBy" TEXT,@@ -211,7 +211,7 @@ CREATE TABLE "customer" ("accountManagerId" TEXT,"logo" TEXT,"assignee" TEXT,- "companyId" INTEGER,+ "companyId" INTEGER NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,"createdBy" TEXT,"updatedAt" TIMESTAMP WITH TIME ZONE,diff --git a/packages/database/supabase/migrations/20230123212853_search.sql b/packages/database/supabase/migrations/20230123212853_search.sqlindex 3522ec9cc9..e816cda02d 100644--- a/packages/database/supabase/migrations/20230123212853_search.sql+++ b/packages/database/supabase/migrations/20230123212853_search.sql@@ -8,7 +8,7 @@ CREATE TABLE search (entity "searchEntity",uuid TEXT,link TEXT NOT NULL,- "companyId" INTEGER,+ "companyId" INTEGER NOT NULL,CONSTRAINT search_uuid_unique UNIQUE (uuid),CONSTRAINT search_companyId_fkey FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE