Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

Replace approverId with approverGroupIds

Sidwebworks94986f7f1329
diff --git a/apps/erp/app/modules/shared/shared.models.ts b/apps/erp/app/modules/shared/shared.models.ts
index b025d06191..37440d06c6 100644
--- a/apps/erp/app/modules/shared/shared.models.ts
+++ b/apps/erp/app/modules/shared/shared.models.ts
@@ -44,8 +44,7 @@ export const approvalRequestValidator = z.object({
documentId: zfd.text(
z.string().min(1, { message: "Document ID is required" })
),
- approverGroupIds: zfd.repeatableOfType(z.string()).optional(),
- approverId: zfd.text(z.string().optional())
+ approverGroupIds: zfd.repeatableOfType(z.string()).optional()
});
export const approvalRuleValidator = z.object({
diff --git a/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsx b/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsx
index b2a0fd3f48..2be27a65de 100644
--- a/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsx
+++ b/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsx
@@ -80,17 +80,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
}
- // Only the creator can edit their own rule
- if (existingRule.createdBy !== userId) {
- throw redirect(
- path.to.approvalRules,
- await flash(
- request,
- error(null, "Only the creator can edit this approval rule")
- )
- );
- }
-
const rulesForType =
rules.data?.filter(
(r) => r.documentType === validation.data.documentType && r.id !== id
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 05119d8c1b..be46e6ae26 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -1692,7 +1692,6 @@ export type Database = {
approvalRequest: {
Row: {
amount: number | null
- approverId: string | null
companyId: string
createdAt: string
createdBy: string
@@ -1710,7 +1709,6 @@ export type Database = {
}
Insert: {
amount?: number | null
- approverId?: string | null
companyId: string
createdAt?: string
createdBy: string
@@ -1728,7 +1726,6 @@ export type Database = {
}
Update: {
amount?: number | null
- approverId?: string | null
companyId?: string
createdAt?: string
createdBy?: string
@@ -1745,41 +1742,6 @@ export type Database = {
updatedBy?: string | null
}
Relationships: [
- {
- foreignKeyName: "approvalRequest_approverId_fkey"
- columns: ["approverId"]
- isOneToOne: false
- referencedRelation: "employees"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "approvalRequest_approverId_fkey"
- columns: ["approverId"]
- isOneToOne: false
- referencedRelation: "employeesAcrossCompanies"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "approvalRequest_approverId_fkey"
- columns: ["approverId"]
- isOneToOne: false
- referencedRelation: "employeeSummary"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "approvalRequest_approverId_fkey"
- columns: ["approverId"]
- isOneToOne: false
- referencedRelation: "user"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "approvalRequest_approverId_fkey"
- columns: ["approverId"]
- isOneToOne: false
- referencedRelation: "userDefaults"
- referencedColumns: ["userId"]
- },
{
foreignKeyName: "approvalRequest_companyId_fkey"
columns: ["companyId"]
@@ -33016,6 +32978,48 @@ export type Database = {
},
]
}
+ searchIndex_KyfnMsRatxt2eAMBNgdxQK: {
+ Row: {
+ createdAt: string
+ description: string | null
+ entityId: string
+ entityType: string
+ id: number
+ link: string
+ metadata: Json | null
+ searchVector: unknown
+ tags: string[] | null
+ title: string
+ updatedAt: string | null
+ }
+ Insert: {
+ createdAt?: string
+ description?: string | null
+ entityId: string
+ entityType: string
+ id?: number
+ link: string
+ metadata?: Json | null
+ searchVector?: unknown
+ tags?: string[] | null
+ title: string
+ updatedAt?: string | null
+ }
+ Update: {
+ createdAt?: string
+ description?: string | null
+ entityId?: string
+ entityType?: string
+ id?: number
+ link?: string
+ metadata?: Json | null
+ searchVector?: unknown
+ tags?: string[] | null
+ title?: string
+ updatedAt?: string | null
+ }
+ Relationships: []
+ }
searchIndexRegistry: {
Row: {
companyId: string
@@ -42680,7 +42684,6 @@ export type Database = {
}
approvalRequests: {
Row: {
- approverId: string | null
companyId: string | null
createdAt: string | null
decisionAt: string | null
@@ -42698,41 +42701,6 @@ export type Database = {
status: Database["public"]["Enums"]["approvalStatus"] | null
}
Relationships: [
- {
- foreignKeyName: "approvalRequest_approverId_fkey"
- columns: ["approverId"]
- isOneToOne: false
- referencedRelation: "employees"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "approvalRequest_approverId_fkey"
- columns: ["approverId"]
- isOneToOne: false
- referencedRelation: "employeesAcrossCompanies"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "approvalRequest_approverId_fkey"
- columns: ["approverId"]
- isOneToOne: false
- referencedRelation: "employeeSummary"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "approvalRequest_approverId_fkey"
- columns: ["approverId"]
- isOneToOne: false
- referencedRelation: "user"
- referencedColumns: ["id"]
- },
- {
- foreignKeyName: "approvalRequest_approverId_fkey"
- columns: ["approverId"]
- isOneToOne: false
- referencedRelation: "userDefaults"
- referencedColumns: ["userId"]
- },
{
foreignKeyName: "approvalRequest_companyId_fkey"
columns: ["companyId"]
@@ -47355,14 +47323,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -52432,14 +52400,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
diff --git a/packages/database/supabase/migrations/20260204204700_drop-approvalRequest-approverId.sql b/packages/database/supabase/migrations/20260204204700_drop-approvalRequest-approverId.sql
new file mode 100644
index 0000000000..f9f16bef37
--- /dev/null
+++ b/packages/database/supabase/migrations/20260204204700_drop-approvalRequest-approverId.sql
@@ -0,0 +1,39 @@
+-- Drop unused approverId column from approvalRequest table
+-- The approval system uses approverGroupIds on approval rules to determine who can approve,
+-- and records the actual decision maker in decisionBy.
+
+-- Drop the view first since it depends on approverId
+DROP VIEW IF EXISTS "approvalRequests";
+
+ALTER TABLE "approvalRequest" DROP CONSTRAINT "approvalRequest_approverId_fkey";
+DROP INDEX "approvalRequest_approverId_idx";
+ALTER TABLE "approvalRequest" DROP COLUMN "approverId";
+
+-- Recreate the view without approverId
+CREATE OR REPLACE VIEW "approvalRequests" WITH (SECURITY_INVOKER=true) AS
+SELECT
+ ar."id",
+ ar."documentType",
+ ar."documentId",
+ ar."status",
+ ar."requestedBy",
+ ar."requestedAt",
+ ar."decisionBy",
+ ar."decisionAt",
+ ar."decisionNotes",
+ ar."companyId",
+ ar."createdAt",
+ CASE
+ WHEN ar."documentType" = 'purchaseOrder' THEN po."purchaseOrderId"
+ WHEN ar."documentType" = 'qualityDocument' THEN qd."name"
+ ELSE NULL
+ END AS "documentReadableId",
+ CASE
+ WHEN ar."documentType" = 'purchaseOrder' THEN s."name"
+ WHEN ar."documentType" = 'qualityDocument' THEN qd."description"
+ ELSE NULL
+ END AS "documentDescription"
+FROM "approvalRequest" ar
+LEFT JOIN "purchaseOrder" po ON ar."documentType" = 'purchaseOrder' AND ar."documentId" = po."id"
+LEFT JOIN "supplier" s ON po."supplierId" = s."id"
+LEFT JOIN "qualityDocument" qd ON ar."documentType" = 'qualityDocument' AND ar."documentId" = qd."id";