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: don't modify existing migrations to change assignee
Brad Barbin16695c2dbd94
diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 6bb056ee8a..bbc14ff6fd 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -14885,196 +14885,6 @@ export type Database = {},]}- serviceSupplier: {- Row: {- active: boolean- companyId: string- createdAt: string- createdBy: string- customFields: Json | null- id: string- serviceId: string- supplierId: string- supplierServiceId: string | null- updatedAt: string | null- updatedBy: string | null- }- Insert: {- active?: boolean- companyId: string- createdAt?: string- createdBy: string- customFields?: Json | null- id?: string- serviceId: string- supplierId: string- supplierServiceId?: string | null- updatedAt?: string | null- updatedBy?: string | null- }- Update: {- active?: boolean- companyId?: string- createdAt?: string- createdBy?: string- customFields?: Json | null- id?: string- serviceId?: string- supplierId?: string- supplierServiceId?: string | null- updatedAt?: string | null- updatedBy?: string | null- }- Relationships: [- {- foreignKeyName: "serviceSupplier_companyId_fkey"- columns: ["companyId"]- isOneToOne: false- referencedRelation: "companies"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_companyId_fkey"- columns: ["companyId"]- isOneToOne: false- referencedRelation: "company"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_companyId_fkey"- columns: ["companyId"]- isOneToOne: false- referencedRelation: "customFieldTables"- referencedColumns: ["companyId"]- },- {- foreignKeyName: "serviceSupplier_companyId_fkey"- columns: ["companyId"]- isOneToOne: false- referencedRelation: "integrations"- referencedColumns: ["companyId"]- },- {- foreignKeyName: "serviceSupplier_createdBy_fkey"- columns: ["createdBy"]- isOneToOne: false- referencedRelation: "employees"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_createdBy_fkey"- columns: ["createdBy"]- isOneToOne: false- referencedRelation: "employeesAcrossCompanies"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_createdBy_fkey"- columns: ["createdBy"]- isOneToOne: false- referencedRelation: "employeeSummary"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_createdBy_fkey"- columns: ["createdBy"]- isOneToOne: false- referencedRelation: "user"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_createdBy_fkey"- columns: ["createdBy"]- isOneToOne: false- referencedRelation: "userDefaults"- referencedColumns: ["userId"]- },- {- foreignKeyName: "serviceSupplier_serviceId_fkey"- columns: ["serviceId", "companyId"]- isOneToOne: false- referencedRelation: "service"- referencedColumns: ["id", "companyId"]- },- {- foreignKeyName: "serviceSupplier_serviceId_fkey"- columns: ["serviceId", "companyId"]- isOneToOne: false- referencedRelation: "services"- referencedColumns: ["id", "companyId"]- },- {- foreignKeyName: "serviceSupplier_supplierId_fkey"- columns: ["supplierId"]- isOneToOne: false- referencedRelation: "contractors"- referencedColumns: ["supplierId"]- },- {- foreignKeyName: "serviceSupplier_supplierId_fkey"- columns: ["supplierId"]- isOneToOne: false- referencedRelation: "partners"- referencedColumns: ["supplierId"]- },- {- foreignKeyName: "serviceSupplier_supplierId_fkey"- columns: ["supplierId"]- isOneToOne: false- referencedRelation: "purchaseOrderSuppliers"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_supplierId_fkey"- columns: ["supplierId"]- isOneToOne: false- referencedRelation: "supplier"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_supplierId_fkey"- columns: ["supplierId"]- isOneToOne: false- referencedRelation: "suppliers"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_updatedBy_fkey"- columns: ["updatedBy"]- isOneToOne: false- referencedRelation: "employees"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_updatedBy_fkey"- columns: ["updatedBy"]- isOneToOne: false- referencedRelation: "employeesAcrossCompanies"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_updatedBy_fkey"- columns: ["updatedBy"]- isOneToOne: false- referencedRelation: "employeeSummary"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_updatedBy_fkey"- columns: ["updatedBy"]- isOneToOne: false- referencedRelation: "user"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_updatedBy_fkey"- columns: ["updatedBy"]- isOneToOne: false- referencedRelation: "userDefaults"- referencedColumns: ["userId"]- },- ]- }shelf: {Row: {active: booleandiff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex 6bb056ee8a..bbc14ff6fd 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -14885,196 +14885,6 @@ export type Database = {},]}- serviceSupplier: {- Row: {- active: boolean- companyId: string- createdAt: string- createdBy: string- customFields: Json | null- id: string- serviceId: string- supplierId: string- supplierServiceId: string | null- updatedAt: string | null- updatedBy: string | null- }- Insert: {- active?: boolean- companyId: string- createdAt?: string- createdBy: string- customFields?: Json | null- id?: string- serviceId: string- supplierId: string- supplierServiceId?: string | null- updatedAt?: string | null- updatedBy?: string | null- }- Update: {- active?: boolean- companyId?: string- createdAt?: string- createdBy?: string- customFields?: Json | null- id?: string- serviceId?: string- supplierId?: string- supplierServiceId?: string | null- updatedAt?: string | null- updatedBy?: string | null- }- Relationships: [- {- foreignKeyName: "serviceSupplier_companyId_fkey"- columns: ["companyId"]- isOneToOne: false- referencedRelation: "companies"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_companyId_fkey"- columns: ["companyId"]- isOneToOne: false- referencedRelation: "company"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_companyId_fkey"- columns: ["companyId"]- isOneToOne: false- referencedRelation: "customFieldTables"- referencedColumns: ["companyId"]- },- {- foreignKeyName: "serviceSupplier_companyId_fkey"- columns: ["companyId"]- isOneToOne: false- referencedRelation: "integrations"- referencedColumns: ["companyId"]- },- {- foreignKeyName: "serviceSupplier_createdBy_fkey"- columns: ["createdBy"]- isOneToOne: false- referencedRelation: "employees"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_createdBy_fkey"- columns: ["createdBy"]- isOneToOne: false- referencedRelation: "employeesAcrossCompanies"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_createdBy_fkey"- columns: ["createdBy"]- isOneToOne: false- referencedRelation: "employeeSummary"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_createdBy_fkey"- columns: ["createdBy"]- isOneToOne: false- referencedRelation: "user"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_createdBy_fkey"- columns: ["createdBy"]- isOneToOne: false- referencedRelation: "userDefaults"- referencedColumns: ["userId"]- },- {- foreignKeyName: "serviceSupplier_serviceId_fkey"- columns: ["serviceId", "companyId"]- isOneToOne: false- referencedRelation: "service"- referencedColumns: ["id", "companyId"]- },- {- foreignKeyName: "serviceSupplier_serviceId_fkey"- columns: ["serviceId", "companyId"]- isOneToOne: false- referencedRelation: "services"- referencedColumns: ["id", "companyId"]- },- {- foreignKeyName: "serviceSupplier_supplierId_fkey"- columns: ["supplierId"]- isOneToOne: false- referencedRelation: "contractors"- referencedColumns: ["supplierId"]- },- {- foreignKeyName: "serviceSupplier_supplierId_fkey"- columns: ["supplierId"]- isOneToOne: false- referencedRelation: "partners"- referencedColumns: ["supplierId"]- },- {- foreignKeyName: "serviceSupplier_supplierId_fkey"- columns: ["supplierId"]- isOneToOne: false- referencedRelation: "purchaseOrderSuppliers"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_supplierId_fkey"- columns: ["supplierId"]- isOneToOne: false- referencedRelation: "supplier"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_supplierId_fkey"- columns: ["supplierId"]- isOneToOne: false- referencedRelation: "suppliers"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_updatedBy_fkey"- columns: ["updatedBy"]- isOneToOne: false- referencedRelation: "employees"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_updatedBy_fkey"- columns: ["updatedBy"]- isOneToOne: false- referencedRelation: "employeesAcrossCompanies"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_updatedBy_fkey"- columns: ["updatedBy"]- isOneToOne: false- referencedRelation: "employeeSummary"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_updatedBy_fkey"- columns: ["updatedBy"]- isOneToOne: false- referencedRelation: "user"- referencedColumns: ["id"]- },- {- foreignKeyName: "serviceSupplier_updatedBy_fkey"- columns: ["updatedBy"]- isOneToOne: false- referencedRelation: "userDefaults"- referencedColumns: ["userId"]- },- ]- }shelf: {Row: {active: booleandiff --git a/packages/database/supabase/migrations/20230330024716_parts.sql b/packages/database/supabase/migrations/20230330024716_parts.sqlindex b1c87e557e..ca4d297948 100644--- a/packages/database/supabase/migrations/20230330024716_parts.sql+++ b/packages/database/supabase/migrations/20230330024716_parts.sql@@ -76,7 +76,6 @@ CREATE TABLE "item" ("active" BOOLEAN NOT NULL DEFAULT true,"blocked" BOOLEAN NOT NULL DEFAULT false,"companyId" TEXT NOT NULL,- "assignee" TEXT,"createdBy" TEXT NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),"updatedBy" TEXT,@@ -86,7 +85,6 @@ CREATE TABLE "item" (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_itemGroupId_fkey" FOREIGN KEY ("itemGroupId") REFERENCES "itemGroup"("id") ON DELETE SET NULL ON UPDATE CASCADE,- CONSTRAINT "item_assignee_fkey" FOREIGN KEY ("assignee") REFERENCES "user"("id") ON UPDATE CASCADE ON DELETE SET NULL,CONSTRAINT "item_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),CONSTRAINT "item_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id"));@@ -221,6 +219,7 @@ CREATE TABLE "part" ("approvedBy" TEXT,"fromDate" DATE,"toDate" DATE,+ "assignee" TEXT,"companyId" TEXT NOT NULL,"createdBy" TEXT NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),@@ -232,6 +231,7 @@ CREATE TABLE "part" (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_approvedBy_fkey" FOREIGN KEY ("approvedBy") REFERENCES "user"("id"),+ CONSTRAINT "part_assignee_fkey" FOREIGN KEY ("assignee") REFERENCES "user"("id") ON UPDATE CASCADE ON DELETE SET NULL,CONSTRAINT "part_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "part_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),CONSTRAINT "part_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id")diff --git a/packages/database/supabase/migrations/20230412120726_services.sql b/packages/database/supabase/migrations/20230412120726_services.sqlindex 90d1b9825a..8b033d2e64 100644--- a/packages/database/supabase/migrations/20230412120726_services.sql+++ b/packages/database/supabase/migrations/20230412120726_services.sql@@ -11,6 +11,7 @@ CREATE TABLE "service" ("approvedBy" TEXT,"fromDate" DATE,"toDate" DATE,+ "assignee" TEXT,"customFields" JSONB,"companyId" TEXT NOT NULL,"createdBy" TEXT NOT NULL,@@ -20,6 +21,7 @@ CREATE TABLE "service" (CONSTRAINT "service_pkey" PRIMARY KEY ("id", "companyId"),CONSTRAINT "service_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "item"("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"),CONSTRAINT "service_approvedBy_fkey" FOREIGN KEY ("approvedBy") REFERENCES "user"("id"),CONSTRAINT "service_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),diff --git a/packages/database/supabase/migrations/20240324175747_assignee.sql b/packages/database/supabase/migrations/20240324175747_assignee.sqlindex 73384162e4..4b77b9284e 100644--- a/packages/database/supabase/migrations/20240324175747_assignee.sql+++ b/packages/database/supabase/migrations/20240324175747_assignee.sql@@ -17,7 +17,6 @@ CREATE OR REPLACE VIEW "parts" WITH(SECURITY_INVOKER=true) ASi."itemInventoryType",i.active,i.blocked,- i.assignee,p.*,pg.name AS "itemGroup",ps."supplierIds",@@ -155,7 +154,6 @@ CREATE OR REPLACE VIEW "services" WITH(SECURITY_INVOKER=true) ASi."itemGroupId",i.active,i.blocked,- i.assignee,pg.name AS "itemGroup",ss."supplierIds"FROM "service" sdiff --git a/packages/database/supabase/migrations/20240601210618_assignee-to-item.sql b/packages/database/supabase/migrations/20240601210618_assignee-to-item.sqlnew file mode 100644index 0000000000..4ff5764842--- /dev/null+++ b/packages/database/supabase/migrations/20240601210618_assignee-to-item.sql@@ -0,0 +1,60 @@+ALTER TABLE "item" ADD COLUMN "assignee" TEXT;+ALTER TABLE "item" ADD CONSTRAINT "item_assignee_fkey" FOREIGN KEY ("assignee") REFERENCES "user"("id") ON UPDATE CASCADE ON DELETE SET NULL;++DROP VIEW "parts";+DROP VIEW "services";++ALTER TABLE "part" DROP CONSTRAINT "part_assignee_fkey";+ALTER TABLE "part" DROP COLUMN "assignee";+ALTER TABLE "service" DROP CONSTRAINT "service_assignee_fkey";+ALTER TABLE "service" DROP COLUMN "assignee";++CREATE OR REPLACE VIEW "parts" WITH(SECURITY_INVOKER=true) AS+ SELECT+ i.name,+ i.description,+ i."itemGroupId",+ i."itemInventoryType",+ i.active,+ i.blocked,+ i.assignee,+ p.*,+ pg.name AS "itemGroup",+ ps."supplierIds",+ uom.name as "unitOfMeasure"+ FROM "part" p+ INNER JOIN "item" i ON i.id = p."itemId"+ LEFT JOIN "itemGroup" pg ON pg.id = i."itemGroupId"+ LEFT JOIN (+ SELECT+ "itemId",+ array_agg(ps."supplierId") AS "supplierIds"+ FROM "itemSupplier" ps+ GROUP BY "itemId"+ ) ps ON ps."itemId" = p."itemId"+ LEFT JOIN "unitOfMeasure" uom ON uom.code = p."unitOfMeasureCode" AND uom."companyId" = p."companyId";+++CREATE OR REPLACE VIEW "services" WITH(SECURITY_INVOKER=true) AS+ SELECT+ s.*,+ i.name,+ i.description,+ i."itemGroupId",+ i.active,+ i.blocked,+ i.assignee,+ pg.name AS "itemGroup",+ ss."supplierIds"+ FROM "service" s+ INNER JOIN "item" i ON i.id = s."itemId"+ LEFT JOIN "itemGroup" pg ON pg.id = i."itemGroupId"+ LEFT JOIN (+ SELECT+ "itemId",+ array_agg(ss."supplierId") AS "supplierIds"+ FROM "itemSupplier" ss+ GROUP BY "itemId"+ ) ss ON ss."itemId" = s."itemId";++DROP TABLE "serviceSupplier";\ No newline at end of filediff --git a/packages/database/supabase/migrations/20240601210618_items.sql b/packages/database/supabase/migrations/20240601210618_items.sqldeleted file mode 100644index 896e77a8e5..0000000000--- a/packages/database/supabase/migrations/20240601210618_items.sql+++ /dev/null@@ -1,59 +0,0 @@----- -- 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