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.

fix: fix migration to rebuild quotes and salesRfqs views

Rob Carringtonbf60fbe5c371
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 0d73bbb4f8..e9b64d6ed2 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -12210,9 +12210,10 @@ export type Database = {
dueDate: string | null
estimatorId: string | null
expirationDate: string | null
+ externalNotes: Json | null
id: string
+ internalNotes: Json | null
locationId: string | null
- notes: Json | null
quoteId: string
revisionId: number
salesPersonId: string | null
@@ -12233,9 +12234,10 @@ export type Database = {
dueDate?: string | null
estimatorId?: string | null
expirationDate?: string | null
+ externalNotes?: Json | null
id?: string
+ internalNotes?: Json | null
locationId?: string | null
- notes?: Json | null
quoteId: string
revisionId?: number
salesPersonId?: string | null
@@ -12256,9 +12258,10 @@ export type Database = {
dueDate?: string | null
estimatorId?: string | null
expirationDate?: string | null
+ externalNotes?: Json | null
id?: string
+ internalNotes?: Json | null
locationId?: string | null
- notes?: Json | null
quoteId?: string
revisionId?: number
salesPersonId?: string | null
@@ -23842,12 +23845,13 @@ export type Database = {
dueDate: string | null
estimatorId: string | null
expirationDate: string | null
+ externalNotes: Json | null
favorite: boolean | null
id: string | null
+ internalNotes: Json | null
lines: number | null
locationId: string | null
locationName: string | null
- notes: Json | null
quoteId: string | null
revisionId: number | null
salesOrderId: string | null
@@ -25031,12 +25035,12 @@ export type Database = {
customFields: Json | null
employeeId: string | null
expirationDate: string | null
+ externalNotes: Json | null
favorite: boolean | null
id: string | null
internalNotes: string | null
locationId: string | null
locationName: string | null
- notes: Json | null
quoteId: string | null
revisionId: number | null
rfqDate: string | null
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 0d73bbb4f8..e9b64d6ed2 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -12210,9 +12210,10 @@ export type Database = {
dueDate: string | null
estimatorId: string | null
expirationDate: string | null
+ externalNotes: Json | null
id: string
+ internalNotes: Json | null
locationId: string | null
- notes: Json | null
quoteId: string
revisionId: number
salesPersonId: string | null
@@ -12233,9 +12234,10 @@ export type Database = {
dueDate?: string | null
estimatorId?: string | null
expirationDate?: string | null
+ externalNotes?: Json | null
id?: string
+ internalNotes?: Json | null
locationId?: string | null
- notes?: Json | null
quoteId: string
revisionId?: number
salesPersonId?: string | null
@@ -12256,9 +12258,10 @@ export type Database = {
dueDate?: string | null
estimatorId?: string | null
expirationDate?: string | null
+ externalNotes?: Json | null
id?: string
+ internalNotes?: Json | null
locationId?: string | null
- notes?: Json | null
quoteId?: string
revisionId?: number
salesPersonId?: string | null
@@ -23842,12 +23845,13 @@ export type Database = {
dueDate: string | null
estimatorId: string | null
expirationDate: string | null
+ externalNotes: Json | null
favorite: boolean | null
id: string | null
+ internalNotes: Json | null
lines: number | null
locationId: string | null
locationName: string | null
- notes: Json | null
quoteId: string | null
revisionId: number | null
salesOrderId: string | null
@@ -25031,12 +25035,12 @@ export type Database = {
customFields: Json | null
employeeId: string | null
expirationDate: string | null
+ externalNotes: Json | null
favorite: boolean | null
id: string | null
internalNotes: string | null
locationId: string | null
locationName: string | null
- notes: Json | null
quoteId: string | null
revisionId: number | null
rfqDate: string | null
diff --git a/packages/database/supabase/migrations/20240823012655_rfq-quote-internal-notes.sql b/packages/database/supabase/migrations/20240823012655_rfq-quote-internal-notes.sql
index e08820185d..f390b9489c 100644
--- a/packages/database/supabase/migrations/20240823012655_rfq-quote-internal-notes.sql
+++ b/packages/database/supabase/migrations/20240823012655_rfq-quote-internal-notes.sql
@@ -1,2 +1,50 @@
+DROP VIEW "salesRfqs";
+
ALTER TABLE "salesRfq"
-RENAME COLUMN "notes" to "externalNotes";
\ No newline at end of file
+ DROP COLUMN "notes",
+ ADD COLUMN "externalNotes" JSON DEFAULT '{}';
+
+
+CREATE OR REPLACE VIEW "salesRfqs" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ rfq.*,
+ l."name" AS "locationName",
+ opp."quoteId",
+ opp."salesOrderId",
+ EXISTS(SELECT 1 FROM "salesRfqFavorite" rf WHERE rf."rfqId" = rfq.id AND rf."userId" = auth.uid()::text) AS favorite
+ FROM "salesRfq" rfq
+ LEFT JOIN "location" l
+ ON l.id = rfq."locationId"
+ LEFT JOIN "opportunity" opp
+ ON opp."salesRfqId" = rfq.id;
+
+
+DROP VIEW "quotes";
+
+ALTER TABLE "quote"
+ DROP COLUMN "notes",
+ ADD COLUMN "externalNotes" JSON DEFAULT '{}',
+ ADD COLUMN "internalNotes" JSON DEFAULT '{}';
+
+CREATE OR REPLACE VIEW "quotes" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ q.*,
+ l."name" AS "locationName",
+ ql."lines",
+ ql."completedLines",
+ EXISTS(SELECT 1 FROM "quoteFavorite" pf WHERE pf."quoteId" = q.id AND pf."userId" = auth.uid()::text) AS favorite,
+ opp."salesRfqId",
+ opp."salesOrderId"
+ FROM "quote" q
+ LEFT JOIN (
+ SELECT
+ "quoteId",
+ COUNT("id") AS "lines",
+ COUNT("id") FILTER (WHERE "status" = 'Complete') AS "completedLines"
+ FROM "quoteLine"
+ GROUP BY "quoteId"
+ ) ql ON ql."quoteId" = q.id
+ LEFT JOIN "location" l
+ ON l.id = q."locationId"
+ LEFT JOIN "opportunity" opp
+ ON opp."quoteId" = q.id;
\ No newline at end of file