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
feat: add item table
Brad Barbinf1c4c570e22c
diff --git a/apps/carbon/app/components/Layout/Navigation/useModules.tsx b/apps/carbon/app/components/Layout/Navigation/useModules.tsxindex 6f9f51cab7..d2703c3c0e 100644--- a/apps/carbon/app/components/Layout/Navigation/useModules.tsx+++ b/apps/carbon/app/components/Layout/Navigation/useModules.tsx@@ -20,7 +20,7 @@ export function useModules() {const modules: Authenticated<NavItem>[] = [{permission: "parts",- name: "Parts",+ name: "Items",to: path.to.partsSearch,icon: LuComponent,},diff --git a/apps/carbon/app/modules/parts/parts.service.ts b/apps/carbon/app/modules/parts/parts.service.tsindex 112903142d..d247b17c3a 100644--- a/apps/carbon/app/modules/parts/parts.service.ts+++ b/apps/carbon/app/modules/parts/parts.service.ts@@ -455,7 +455,28 @@ export async function upsertPart(})) {if ("createdBy" in part) {- return client.from("part").insert(part).select("*").single();+ const itemInsert = await client+ .from("item")+ .insert({+ readableId: part.id,+ name: part.name,+ type: "part",+ companyId: part.companyId,+ createdBy: part.createdBy,+ })+ .select("id")+ .single();+ if (itemInsert.error) return itemInsert;+ const itemId = itemInsert.data?.id;++ return client+ .from("part")+ .insert({+ ...part,+ itemId,+ })+ .select("*")+ .single();}return client.from("part")diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex c18e725cc6..614e7ad3cf 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -5412,6 +5412,110 @@ export type Database = {}Relationships: []}+ item: {+ Row: {+ companyId: string+ createdAt: string+ createdBy: string+ id: string+ name: string+ partGroupId: string | null+ readableId: string+ type: Database["public"]["Enums"]["itemType"]+ }+ Insert: {+ companyId: string+ createdAt?: string+ createdBy: string+ id?: string+ name: string+ partGroupId?: string | null+ readableId: string+ type: Database["public"]["Enums"]["itemType"]+ }+ Update: {+ companyId?: string+ createdAt?: string+ createdBy?: string+ id?: string+ name?: string+ partGroupId?: string | null+ readableId?: string+ type?: Database["public"]["Enums"]["itemType"]+ }+ Relationships: [+ {+ foreignKeyName: "item_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "companies"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "company"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "customFieldTables"+ referencedColumns: ["companyId"]+ },+ {+ foreignKeyName: "item_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "integrations"+ referencedColumns: ["companyId"]+ },+ {+ foreignKeyName: "item_createdBy_fkey"+ columns: ["createdBy"]+ isOneToOne: false+ referencedRelation: "employees"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_createdBy_fkey"+ columns: ["createdBy"]+ isOneToOne: false+ referencedRelation: "employeesAcrossCompanies"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_createdBy_fkey"+ columns: ["createdBy"]+ isOneToOne: false+ referencedRelation: "employeeSummary"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_createdBy_fkey"+ columns: ["createdBy"]+ isOneToOne: false+ referencedRelation: "user"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_createdBy_fkey"+ columns: ["createdBy"]+ isOneToOne: false+ referencedRelation: "userDefaults"+ referencedColumns: ["userId"]+ },+ {+ foreignKeyName: "item_partGroupId_fkey"+ columns: ["partGroupId"]+ isOneToOne: false+ referencedRelation: "partGroup"+ referencedColumns: ["id"]+ },+ ]+ }journal: {Row: {accountingPeriodId: string | null@@ -5855,6 +5959,7 @@ export type Database = {description: string | nullfromDate: string | nullid: string+ itemId: stringmanufacturerPartNumber: string | nullname: stringpartGroupId: string | null@@ -5878,6 +5983,7 @@ export type Database = {description?: string | nullfromDate?: string | nullid: string+ itemId: stringmanufacturerPartNumber?: string | nullname: stringpartGroupId?: string | null@@ -5901,6 +6007,7 @@ export type Database = {description?: string | nullfromDate?: string | nullid?: string+ itemId?: stringmanufacturerPartNumber?: string | nullname?: stringpartGroupId?: string | null@@ -6045,6 +6152,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "part_id_fkey"+ columns: ["itemId"]+ isOneToOne: false+ referencedRelation: "item"+ referencedColumns: ["id"]+ },{foreignKeyName: "part_partGroupId_fkey"columns: ["partGroupId"]@@ -19716,6 +19830,7 @@ export type Database = {description: string | nullfromDate: string | nullid: string | null+ itemId: string | nullmanufacturerPartNumber: string | nullname: string | nullpartGroup: string | null@@ -19864,6 +19979,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "part_id_fkey"+ columns: ["itemId"]+ isOneToOne: false+ referencedRelation: "item"+ referencedColumns: ["id"]+ },{foreignKeyName: "part_partGroupId_fkey"columns: ["partGroupId"]@@ -22935,6 +23057,14 @@ export type Database = {glAccountType: "Posting" | "Total" | "Begin Total" | "End Total"glConsolidatedRate: "Average" | "Current" | "Historical"glIncomeBalance: "Balance Sheet" | "Income Statement"+ itemType:+ | "part"+ | "material"+ | "tool"+ | "hardware"+ | "service"+ | "consumable"+ | "fixture"journalLineDocumentType:| "Receipt"| "Invoice"diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex c18e725cc6..614e7ad3cf 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -5412,6 +5412,110 @@ export type Database = {}Relationships: []}+ item: {+ Row: {+ companyId: string+ createdAt: string+ createdBy: string+ id: string+ name: string+ partGroupId: string | null+ readableId: string+ type: Database["public"]["Enums"]["itemType"]+ }+ Insert: {+ companyId: string+ createdAt?: string+ createdBy: string+ id?: string+ name: string+ partGroupId?: string | null+ readableId: string+ type: Database["public"]["Enums"]["itemType"]+ }+ Update: {+ companyId?: string+ createdAt?: string+ createdBy?: string+ id?: string+ name?: string+ partGroupId?: string | null+ readableId?: string+ type?: Database["public"]["Enums"]["itemType"]+ }+ Relationships: [+ {+ foreignKeyName: "item_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "companies"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "company"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "customFieldTables"+ referencedColumns: ["companyId"]+ },+ {+ foreignKeyName: "item_companyId_fkey"+ columns: ["companyId"]+ isOneToOne: false+ referencedRelation: "integrations"+ referencedColumns: ["companyId"]+ },+ {+ foreignKeyName: "item_createdBy_fkey"+ columns: ["createdBy"]+ isOneToOne: false+ referencedRelation: "employees"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_createdBy_fkey"+ columns: ["createdBy"]+ isOneToOne: false+ referencedRelation: "employeesAcrossCompanies"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_createdBy_fkey"+ columns: ["createdBy"]+ isOneToOne: false+ referencedRelation: "employeeSummary"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_createdBy_fkey"+ columns: ["createdBy"]+ isOneToOne: false+ referencedRelation: "user"+ referencedColumns: ["id"]+ },+ {+ foreignKeyName: "item_createdBy_fkey"+ columns: ["createdBy"]+ isOneToOne: false+ referencedRelation: "userDefaults"+ referencedColumns: ["userId"]+ },+ {+ foreignKeyName: "item_partGroupId_fkey"+ columns: ["partGroupId"]+ isOneToOne: false+ referencedRelation: "partGroup"+ referencedColumns: ["id"]+ },+ ]+ }journal: {Row: {accountingPeriodId: string | null@@ -5855,6 +5959,7 @@ export type Database = {description: string | nullfromDate: string | nullid: string+ itemId: stringmanufacturerPartNumber: string | nullname: stringpartGroupId: string | null@@ -5878,6 +5983,7 @@ export type Database = {description?: string | nullfromDate?: string | nullid: string+ itemId: stringmanufacturerPartNumber?: string | nullname: stringpartGroupId?: string | null@@ -5901,6 +6007,7 @@ export type Database = {description?: string | nullfromDate?: string | nullid?: string+ itemId?: stringmanufacturerPartNumber?: string | nullname?: stringpartGroupId?: string | null@@ -6045,6 +6152,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "part_id_fkey"+ columns: ["itemId"]+ isOneToOne: false+ referencedRelation: "item"+ referencedColumns: ["id"]+ },{foreignKeyName: "part_partGroupId_fkey"columns: ["partGroupId"]@@ -19716,6 +19830,7 @@ export type Database = {description: string | nullfromDate: string | nullid: string | null+ itemId: string | nullmanufacturerPartNumber: string | nullname: string | nullpartGroup: string | null@@ -19864,6 +19979,13 @@ export type Database = {referencedRelation: "userDefaults"referencedColumns: ["userId"]},+ {+ foreignKeyName: "part_id_fkey"+ columns: ["itemId"]+ isOneToOne: false+ referencedRelation: "item"+ referencedColumns: ["id"]+ },{foreignKeyName: "part_partGroupId_fkey"columns: ["partGroupId"]@@ -22935,6 +23057,14 @@ export type Database = {glAccountType: "Posting" | "Total" | "Begin Total" | "End Total"glConsolidatedRate: "Average" | "Current" | "Historical"glIncomeBalance: "Balance Sheet" | "Income Statement"+ itemType:+ | "part"+ | "material"+ | "tool"+ | "hardware"+ | "service"+ | "consumable"+ | "fixture"journalLineDocumentType:| "Receipt"| "Invoice"diff --git a/packages/database/supabase/migrations/20230330024716_parts.sql b/packages/database/supabase/migrations/20230330024716_parts.sqlindex c173339f88..b0e1e79b3b 100644--- a/packages/database/supabase/migrations/20230330024716_parts.sql+++ b/packages/database/supabase/migrations/20230330024716_parts.sql@@ -50,6 +50,35 @@ CREATE POLICY "Employees with parts_delete can delete part groups" ON "partGrouphas_company_permission('parts_update', "companyId"));++CREATE TYPE "itemType" AS ENUM (+ 'part',+ 'material',+ 'tool',+ 'hardware',+ 'service',+ 'consumable',+ 'fixture'+);++CREATE TABLE "item" (+ "id" TEXT NOT NULL DEFAULT xid(),+ "readableId" TEXT NOT NULL,+ "name" TEXT NOT NULL,+ "type" "itemType" NOT NULL,+ "partGroupId" TEXT,+ "companyId" TEXT NOT NULL,+ "createdBy" TEXT NOT NULL,+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),++ CONSTRAINT "item_pkey" PRIMARY KEY (id),+ CONSTRAINT "item_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "item_unique" UNIQUE ("readableId", "companyId", "type"),+ CONSTRAINT "item_partGroupId_fkey" FOREIGN KEY ("partGroupId") REFERENCES "partGroup"("id") ON DELETE SET NULL ON UPDATE CASCADE,+ CONSTRAINT "item_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id")+);++CREATE TYPE "partType" AS ENUM ('Inventory','Non-Inventory'@@ -139,6 +168,7 @@ CREATE POLICY "Employees with parts_delete can delete units of measure" ON "unitCREATE TABLE "part" ("id" TEXT NOT NULL,+ "itemId" TEXT NOT NULL,"name" TEXT NOT NULL,"description" TEXT,"blocked" BOOLEAN NOT NULL DEFAULT false,@@ -161,6 +191,7 @@ CREATE TABLE "part" ("customFields" JSONB,CONSTRAINT "part_pkey" PRIMARY KEY ("id", "companyId"),+ CONSTRAINT "part_id_fkey" FOREIGN KEY ("itemId") REFERENCES "item"("id") ON DELETE CASCADE ON UPDATE CASCADE,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"),diff --git a/packages/database/supabase/migrations/20240601210618_items.sql b/packages/database/supabase/migrations/20240601210618_items.sqlnew file mode 100644index 0000000000..896e77a8e5--- /dev/null+++ b/packages/database/supabase/migrations/20240601210618_items.sql@@ -0,0 +1,59 @@+++-- -- Create the part table+-- CREATE TABLE part (+-- id TEXT NOT NULL,+++-- FOREIGN KEY (item_id) REFERENCES item(id)+-- );++-- -- Create the material table+-- CREATE TABLE material (+-- id TEXT NOT NULL,,+-- item_id INT NOT NULL,+-- type VARCHAR(255) NOT NULL,+-- dimension VARCHAR(255) NOT NULL,+-- -- Add other columns specific to materials+-- FOREIGN KEY (item_id) REFERENCES item(id)+-- );++-- -- Create the tool table+-- CREATE TABLE tool (+-- id TEXT NOT NULL,,+-- item_id INT NOT NULL,+-- -- Add other columns specific to tools+-- FOREIGN KEY (item_id) REFERENCES item(id)+-- );++-- -- Create the hardware table+-- CREATE TABLE hardware (+-- id TEXT NOT NULL,,+-- item_id INT NOT NULL,+-- -- Add other columns specific to hardware+-- FOREIGN KEY (item_id) REFERENCES item(id)+-- );++-- -- Create the service table+-- CREATE TABLE service (+-- id TEXT NOT NULL,,+-- item_id INT NOT NULL,+-- -- Add other columns specific to services+-- FOREIGN KEY (item_id) REFERENCES item(id)+-- );++-- -- Create the consumable table+-- CREATE TABLE consumable (+-- id TEXT NOT NULL,,+-- item_id INT NOT NULL,+-- -- Add other columns specific to consumables+-- FOREIGN KEY (item_id) REFERENCES item(id)+-- );++-- -- Create the fixture table+-- CREATE TABLE fixture (+-- id TEXT NOT NULL,,+-- item_id INT NOT NULL,+-- -- Add other columns specific to fixtures+-- FOREIGN KEY (item_id) REFERENCES item(id)+-- );\ No newline at end of file