WFDASH-WEBAPP/scripts/migrations
SJCoetz db1e7d6f76 perf(quotes): server-side tab filter, slim expand, combined counts + bonus bugfix
Same shape as the orders refactor \u2014 applied to the quotes page,
with a fix for a long-standing tab-count bug along the way.

# Measured against the live PB (8,466 quotes, 4,514 orders, 25,612 items)

Before:
  - 22 parallel per-status getList(1, 1) queries for the badge
    counts: 2.6s wall time (no quotes.status index)
  - 64 KB JSON response for 20 quotes with full deep-expand
    (45+ fields per quote, including unbounded email_body)
  - Page footer shows 'Page 1 of N' where N is the global count
    \u2014 'Completed' tab had 7,849 quotes = 'Page 1 of 393'

After (no PB index, just code):
  - 1 combined counts query: 138ms (19x faster)
  - 5.5 KB JSON response (12x smaller)
  - Server-side tab filter: page 1 of N reflects the tab's set
  - Cancelled tab badge now correctly counts rejected+cancelled

# Server-side read model

- getQuotesDashboardData in src/lib/server/quotes-service.ts
  - tab-scoped list + global counts in one round-trip
  - tab param drives a server-side filter (status IN (...) for
    workflow tabs, relation filter for delivery_note, is_template
    for templates, excludeTemplate for 'all')
  - pagination reflects the active tab's matching set, not the
    global ~8.5k quote count

- getQuoteStatusTabCounts: one combined getFullList with all
  17 counted statuses ORed (fields: 'status'), deduped in memory.
  Replaces 22 separate per-status scans. Cached 60s on the server
  with bypassCache option for future realtime refetches.

- /api/v1/quotes/list thin route: validates tab against
  QUOTE_TAB_ORDER, threads tab + nocache params to the service.

# Slim wire payload

- fields param on the orders list: just the columns the page reads
  + per-expand limits (quote.quote_number doesn't need
  email_body, company.company doesn't need its address field, etc.)
- Dropped the customer.company 3-level expand (the page never read
  expand.customer.expand.company \u2014 only expand.company.company,
  which is a direct relation from quote)
- searchQuotesWithItems: same fields added, with
  fetchQuoteItemsForQuotes now accepting fields

# Bonus bug: 'Cancelled' tab badge was always empty

The old getQuoteStatusCounts mapped both 'cancelled' AND 'rejected'
to the 'completed' count, so the page's 'Cancelled' tab badge
showed 0 even when 60+ rejected quotes existed. The page's
tabFilters separately grouped them under 'cancelled', so a quote
that was rejected showed up in the list but not the count.

The new QUOTE_TAB_STATUSES in the service layer is the canonical
mapping (cancelled absorbs both statuses). Page constants and
service constants now derive from the same source \u2014 no more drift.

# Index migration

scripts/migrations/2026-08-04-add-quotes-status-index.ts. Idempotent.
The live PB has no quotes.status index today (verified by hitting
/api/collections/quotes). With the index, the combined counts
query drops from 138ms to sub-10ms on the live instance.

# Tests

6 new tests in quotes-service.test.ts:
  - QUOTE_TAB_STATUSES contract (cancelled absorbs rejected,
    no empty status lists unless special-cased)
  - getQuoteStatusTabCounts buckets correctly into tabs
  - Cache hit returns the same counts on second call
  - bypassCache: true sees new state
  - getQuotesDashboardData end-to-end: tab-scoped items +
    global counts
  - Regression guard for the cancelled/rejected bug

Mock infrastructure upgrade: the quotes-service mock's where
function is now a proper recursive-descent filter parser (handles
nested || inside parens, empty quoted values). getList mock now
returns totalPages.

Full suite: 1312/1312 pass.

Co-authored-by: Orca <help@stably.ai>
2026-08-04 19:01:31 +02:00
..
2026-06-23-add-quote-attachments-direction.ts feat: add quote templates, improved email, new statuses 2026-06-24 22:57:01 +02:00
2026-06-23-add-quote-email-composition-fields.ts feat: add quote templates, improved email, new statuses 2026-06-24 22:57:01 +02:00
2026-06-23-add-quote-outbound-email-fields.ts feat: add quote templates, improved email, new statuses 2026-06-24 22:57:01 +02:00
2026-06-23-add-quote-template-fields.ts feat: add quote templates, improved email, new statuses 2026-06-24 22:57:01 +02:00
2026-06-26-add-orders-rep.ts refactor: drop order-level status, shift to item-driven workflow 2026-06-29 13:06:01 +02:00
2026-06-27-add-order-quote-match-fields.ts refactor: drop order-level status, shift to item-driven workflow 2026-06-29 13:06:01 +02:00
2026-06-27-drop-orders-status-and-wipe.ts refactor: drop order-level status, shift to item-driven workflow 2026-06-29 13:06:01 +02:00
2026-06-28-add-companies-coordinates.ts refactor: drop order-level status, shift to item-driven workflow 2026-06-29 13:06:01 +02:00
2026-06-28-add-purchase-order-pdfs.ts refactor: drop order-level status, shift to item-driven workflow 2026-06-29 13:06:01 +02:00
2026-06-28-convert-customer-fields.ts refactor: drop order-level status, shift to item-driven workflow 2026-06-29 13:06:01 +02:00
2026-06-30-add-price-list-search-text.ts feat(pricelist): Catalogue search hits every field (incl. synonyms) 2026-06-30 12:10:27 +02:00
2026-06-30-add-price-list-sku-normalised.ts feat: implement sku-based catalogue pricing matching workflow 2026-06-30 21:20:53 +02:00
2026-06-30-add-price-list-source-file.ts feat(pricelist): Catalogue tab with search + category/brand filters 2026-06-30 11:49:48 +02:00
2026-06-30-add-pricelist-notes.ts feat(pricelist): notes field for AI instructions + file_name on upload 2026-06-30 11:09:27 +02:00
2026-06-30-add-quote-items-sku-and-pricing.ts feat: implement sku-based catalogue pricing matching workflow 2026-06-30 21:20:53 +02:00
2026-06-30-add-raw-price-list.ts feat(management): new Pricelist page with drag-drop upload + queue table 2026-06-30 09:14:36 +02:00
2026-06-30-backfill-price-list-search-text.ts feat: implement sku-based catalogue pricing matching workflow 2026-06-30 21:20:53 +02:00
2026-06-30-create-rfq-outbound.ts feat: implement sku-based catalogue pricing matching workflow 2026-06-30 21:20:53 +02:00
2026-07-02-add-sprint-categories-and-claims.ts feat(sprint): add new sprint pricing workflow and supporting code 2026-07-03 07:29:43 +02:00
2026-07-06-order-items-assigned-at.ts refactor: switch hardcoded UI colors to semantic theme tokens 2026-07-07 17:22:03 +02:00
2026-07-06-order-items-collection-pool-rename.ts refactor: switch hardcoded UI colors to semantic theme tokens 2026-07-07 17:22:03 +02:00
2026-07-06-order-items-nullable-numbers.ts refactor: switch hardcoded UI colors to semantic theme tokens 2026-07-07 17:22:03 +02:00
2026-07-06-order-items-pricing-fields.ts refactor: switch hardcoded UI colors to semantic theme tokens 2026-07-07 17:22:03 +02:00
2026-07-06-purchase-orders-documents-field.ts refactor: switch hardcoded UI colors to semantic theme tokens 2026-07-07 17:22:03 +02:00
2026-07-06-purchase-orders-send-fields.ts refactor: switch hardcoded UI colors to semantic theme tokens 2026-07-07 17:22:03 +02:00
2026-07-06-quote-attachments-quote-item-and-kind.ts refactor: switch hardcoded UI colors to semantic theme tokens 2026-07-07 17:22:03 +02:00
2026-07-07-backfill-assigned-rfc.ts refactor: update pool UI, fix tiles and config 2026-07-07 18:01:43 +02:00
2026-07-07-order-items-collection-photo.ts feat(collection-pool): add unified redesigned collection pool view 2026-07-07 20:49:31 +02:00
2026-07-07-order-items-ready-for-collection.ts refactor: switch hardcoded UI colors to semantic theme tokens 2026-07-07 17:22:03 +02:00
2026-07-09-po-additional-attachments.ts feat(po-attachments): add migration for additional_attachments field 2026-07-09 23:22:23 +02:00
2026-07-09-po-pdf-tokens.ts feat(po-pdf): add token backfill migration script 2026-07-09 22:28:50 +02:00
2026-07-10-restore-counters.ts fix, feat, style: standardize quote numbers, polish UI 2026-07-10 22:21:50 +02:00
2026-07-14-create-stock-purchases.ts feat(stock): implement stock management workflow 2026-07-15 21:53:20 +02:00
2026-07-14-create-stock.ts feat(stock): implement stock management workflow 2026-07-15 21:53:20 +02:00
2026-07-15-add-stock-items-target-qty.ts feat(stock): implement stock management workflow 2026-07-15 21:53:20 +02:00
2026-07-15-add-stock-line-drv-id.ts feat: add stock line support to collection pool 2026-07-16 20:41:42 +02:00
2026-07-15-stock-purchase-line-state.ts feat: add stock line support to collection pool 2026-07-16 20:41:42 +02:00
2026-07-16-add-stock-purchase-documents-history.ts feat(stock-purchases,driver-app): add stock purchase workflow and driver pickup support 2026-07-18 22:43:50 +02:00
2026-07-16-add-stock-purchase-send-statuses.ts feat(stock-purchases,driver-app): add stock purchase workflow and driver pickup support 2026-07-18 22:43:50 +02:00
2026-07-17-add-stock-purchase-problem-fields.ts feat(stock-purchases,driver-app): add stock purchase workflow and driver pickup support 2026-07-18 22:43:50 +02:00
2026-07-19-create-delivery-notes.ts chore: add logos, opencode config and build assets 2026-07-27 08:21:20 +02:00
2026-07-19-delivery-notes-signed-copy.ts chore: add logos, opencode config and build assets 2026-07-27 08:21:20 +02:00
2026-07-19-delivery-notes-v3.ts chore: add logos, opencode config and build assets 2026-07-27 08:21:20 +02:00
2026-07-20-delivery-tracking.ts chore: add logos, opencode config and build assets 2026-07-27 08:21:20 +02:00
2026-07-24-partial-approval.ts chore: add logos, opencode config and build assets 2026-07-27 08:21:20 +02:00
2026-07-25-add-ai-insights-fields.ts chore: add logos, opencode config and build assets 2026-07-27 08:21:20 +02:00
2026-07-26-fix-quote-counter-and-reassign-numbers.ts fix(api,layout): sprint 500 chunk + add 9 missing top-level agent routes + metadataBase; drop unused collection_pool feature; quote counter fix migration 2026-07-26 22:18:49 +02:00
2026-08-03-add-stock-pricing-and-cost-history.ts feat: unify buyer task flows by supporting both customer orders and stock purchases in mark-ready API and UI, and fix PDF table layout responsiveness. 2026-08-03 18:52:30 +02:00
2026-08-04-add-order-items-item-status-index.ts perf(orders): server-side tab filter, slim expand payload, single combined count query 2026-08-04 18:17:59 +02:00
2026-08-04-add-quotes-status-index.ts perf(quotes): server-side tab filter, slim expand, combined counts + bonus bugfix 2026-08-04 19:01:31 +02:00
add-quote-items-user-edited.ts feat: add AI quote item rewriter and supporting UI/UX changes 2026-06-22 18:29:59 +02:00
broaden-quote-attachments-mime-types.ts feat(quotes): add email-to-quote pipeline with attachments and replies 2026-06-16 20:46:28 +02:00
create-order-items-v2-and-collection-pool.ts chore: standardize line endings and add full test + config scaffolding 2026-06-11 20:30:02 +02:00
create-quote-attachments-and-replies.ts feat(quotes): add email-to-quote pipeline with attachments and replies 2026-06-16 20:46:28 +02:00