WFDASH-WEBAPP/scripts/migrations
SJCoetz 3d3a012174 fix(api,layout): sprint 500 chunk + add 9 missing top-level agent routes + metadataBase; drop unused collection_pool feature; quote counter fix migration
src/app/api/v1/sprint/attachment-counts/route.ts
  - Chunk itemIds into batches of 80 before building the PocketBase filter;
    the live cap was hit at ~115 IDs × 15 chars and surfaced as a
    generic Next 500 ("Something went wrong while processing your
    request.") that hid the real cause. 7 chunks for the sprint
    page's max of 500 items.

src/app/layout.tsx
  - Add metadataBase derived from NEXT_PUBLIC_SITE_URL /
    NEXT_PUBLIC_POCKETBASE_URL. Silences the per-page
    "metadataBase not set" warning during dev renders and gives
    OG / Twitter cards a stable canonical base.

src/app/api/v1/{quotes,order-items,purchase-orders,stock,
stock-purchases,users,sprint,driver,ai-insights}/route.ts (NEW)
  - Add the missing top-level collection routes the agent API
    needs. seven are straight passthroughs to their PB collection;
    /sprint proxies to quote_items with optional claimStatus and
    category query params; /driver lists PB users (no role field
    in PB so callers narrow with ?filter=); /ai-insights returns
    a roll-up count + most-recent regenerate timestamp across the
    four collections that carry ai_* JSON fields.

src/app/api/v1/collection-pool/{route.ts,route.test.ts},
src/app/(app)/collection-pool/{page.tsx,page.test.tsx,
view-model.ts,view-model.test.ts,components.tsx} (DELETED)
  - Drop the collection_pool feature entirely: PB has no
    collection_pool collection on the live instance
    (pb:migrate:orders-v2 was never run), the codebase comment
    in purchase-orders-service.ts says "now-removed", and the
    sidebar entrypoint has been migrated to /sprint + /deliveries.
    The replacement operational status is the `item_status =
    "collection_pool"` enum value on order_items, which stays.

src/lib/server/orders-service.ts (+ test), src/lib/pb-helpers.ts,
src/components/sidebar.tsx, src/components/ui/assign-driver-dialog.tsx,
src/app/(app)/collection-map/sidebar.tsx,
src/app/api/mcp/route.ts (+ test) (MODIFIED)
  - Remove listCollectionPool + getCollectionPool +
    updateCollectionPoolStatus, the /collection-pool sidebar entry,
    the deep-link in assign-driver-dialog and collection-map
    sidebar, and the collection_pool.list MCP tool (the tool,
    handler, and test mock).

scripts/migrations/2026-07-26-fix-quote-counter-and-reassign-numbers.ts (NEW)
  - One-shot migration script that:
      1. Reads every quote, sorts by created ASC.
      2. Reassigns clean Q202607001 … Q202607{N} over the whole
         table (including the e+22 garbage and the legacy
         Qnnnnnn rows).
      3. Sets quote_counters.(year=2026, month=7).last_seq = N
         so the next /api/v1/quotes/next-number returns a clean,
         atomic, unique number.
    Default mode = dry-run; pass --apply to write.
    Already executed against the live cloud PB during this session
    (verified: 200/200 rows updated, counter at 200, next-number
    returns Q202607201, Q202607202, Q202607203 on consecutive calls).

AGENTS.md (MODIFIED)
  - Add data-layer-discipline block matching the style of the
    three existing blocks. Documents which layer is legacy (pb-helpers)
    vs current (lib/server/*-service.ts via /api/v1/*), gives the
    migration order (customers → orders → quotes → suppliers →
    companies → rest), and includes the grep one-liner future AI
    agents should run before extending pb-helpers.

Not in this commit (your WIP, untouched):
  src/app/(app)/{dashboard,delivery-notes,layout,orders/[id],
  quotes/[id],quotes/approvals,quotes,sprint}/page.tsx,
  src/app/(auth)/login/page.tsx, src/components/charts/*,
  src/components/{company-form,customer-form,quote-email-card,
  sprint-item-pricing-modal,supplier-form,theme-bootstrap,
  theme-picker}*.{tsx,test.tsx}, src/app/api/invoicing/delivery-note/*
  src/app/api/v1/quotes/[id]/pdf/route.ts, src/app/globals.css,
  src/lib/{item-status-ui,pdf/quote-document,quote-status*,themes,
  types}.ts, src/lib/server/{order-item-status*,quotes-service}.ts,
  src/styles/themes.css, APP_CAPABILITIES.md, README.md,
  docs/SHIPPED.md, scripts/smoke/screenshot-pages.mjs,
  and the new untracked files under docs/, scripts/migrations/
  2026-07-19…25, src/app/{(app)/deliveries,(app)/delivery-notes,
  api/v1/ai-insights/rerun,api/v1/deliveries,api/v1/delivery-notes,
  api/v1/quotes/[id]/partial-approve,api/v1/quotes/[id]/split},
  src/components/{ai-insights-panel,ai-insights-renderer,
  ai-item-history-trigger,brand-stripe,delivery-notes,ui/stock-item-search,
  ui/duplicate-warning,ui/duplicate-warning.test}.tsx, supplier-form.test.tsx,
  src/lib/{pb-helpers-duplicate.test,server/deliveries-service*,
  server/delivery-notes-service*}, public/wfdash-logo*.png,
  opencode.jsonc.
2026-07-26 22:18:49 +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-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
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