Commit Graph

149 Commits

Author SHA1 Message Date
HoloPanio a106bb15a8 fix(ci): explicit env vars in dalpuri sync job; add CW_DATABASE_URL to secret
envFrom was loading api-env-secret but CW_DATABASE_URL was absent from the
deployed secret, causing sync.ts to fall back to DATABASE_URL (Postgres) as
the MSSQL connection string -> 'Invalid port number: //optima'.

- Replaced envFrom with explicit CW_DATABASE_URL and API_DATABASE_URL env
  entries so the mapping is unambiguous
- Patched api-env-secret in cluster to add CW_DATABASE_URL
v0.1.30
2026-04-08 20:41:49 +00:00
HoloPanio d9a431d99a fix(ci): sync-cw-to-api must wait for migrate-api to complete
Migration must finish before sync runs so the schema exists.
v0.1.29
2026-04-08 20:27:05 +00:00
HoloPanio 83377a7d0d feat(ci): run dalpuri CW-to-API sync as a k8s Job before deploy
The CW MSSQL and API Postgres addresses are internal to the cluster and
unreachable from GitHub-hosted runners, so the sync must run inside k8s.

- Add dalpuri-sync Docker stage to api/Dockerfile: installs deps,
  generates both Prisma clients, and runs dalpuri/src/sync.ts
- Add dalpuri/kubernetes/sync-job.yaml: mounts api-env-secret (which
  already contains CW_DATABASE_URL) and maps DATABASE_URL -> API_DATABASE_URL
- build-api job now also pushes optima-dalpuri-sync:TAG image
- sync-cw-to-api CI job replaced with kubectl apply/wait pattern,
  needs [build-api, build-worker], blocks deploy-api and deploy-worker
v0.1.28
2026-04-08 20:19:06 +00:00
HoloPanio a81618007c fix(worker): pass socket to enqueueDalpuriFullSync
The socket retrieved from ensureManagerSocketReady() was never passed to
enqueueDalpuriFullSync(), so inside createWorkerJob the socket.emit('requestId')
call crashed with 'TypeError: undefined is not an object (evaluating A.emit)'.

This caused every full sync job to fail immediately, leaving the DB empty.
The 5s incremental sync interval then flooded the queue with 4700+ jobs that
all failed too since there was no data.

Also manually cleared the backlog of 4720 failed/pending incremental jobs and
2 failed full sync jobs from the production queue.
v0.1.27
2026-04-08 19:34:33 +00:00
HoloPanio f56c49e242 fix(migrate): handle existing Company/UnifiSite data in catch-up migration
Two bugs in the catch-up migration that only manifest with real production data:

1. Company (4520 rows): uid was added as TEXT NOT NULL DEFAULT '' causing
   all existing rows to get uid='' which makes the PRIMARY KEY constraint
   fail with 'could not create unique index, Key (uid)=() is duplicated'.
   Fix: add uid as nullable, UPDATE uid = id (copies the existing CUID text
   PK into uid), then SET NOT NULL, then swap PK. Also populate the new
   integer id column from cw_CompanyId (which is fully populated in prod).

2. UnifiSite (180 rows): old approach just dropped the text companyId and
   added a null integer column, destroying all company relationships.
   Fix: add companyId_int, UPDATE via JOIN on Company.uid (= old Company.id
   text), drop old text column, rename integer column.

Also fix the P3009 handler in migrate-entrypoint.sh: Prisma may emit ANSI
color codes even without a TTY, wrapping backticks in escape sequences and
breaking the regex match. Fix: strip ANSI codes with sed before extracting
the migration name. Also simplify the regex from a rigid format match to a
simpler backtick-content grep.

Production DB manually unblocked (migrate resolve --rolled-back) so the
next deploy will cleanly apply the corrected migration.
v0.1.26
2026-04-08 18:07:16 +00:00
HoloPanio 4fa13a1d28 fix(migrate): fix set -e swallowing prisma output on failure
POSIX sh exits a script on the assignment line when command substitution
exits non-zero under set -e -- before the subsequent echo ever runs.

  DEPLOY_OUTPUT=$(cmd 2>&1)   # <- script exits here if cmd fails
  EXIT_CODE=$?
  echo "$DEPLOY_OUTPUT"       # <- never reached

Fix: use the || idiom, which puts the LHS in a compound-command context
where set -e does not apply, and still captures the real exit code:

  EXIT_CODE=0
  DEPLOY_OUTPUT=$(cmd 2>&1) || EXIT_CODE=$?
  echo "$DEPLOY_OUTPUT"       # <- always runs

Applied the same fix to the resolve call.
v0.1.25
2026-04-08 14:31:22 +00:00
HoloPanio 6b90bab30c fix(api): add catch-up migration to sync db-push schema drift
All schema changes that were applied via 'prisma db push' over the past
several months were never captured in migration files.  When the postgres
pod restarted just before the migration job ran, the database was rebuilt
from the 15 existing migrations -- creating an old schema that was missing
~20 tables and significant structural changes to User, Opportunity,
CatalogItem, and Company.

This migration bridges the gap idempotently:
- New enums: PhoneType, FaxType, BillingMethod, BillingType, GenderType,
  USState, Country, OpportunityInterest
- User: add firstName/lastName/title/active/hidden/cwMemberId/updatedBy;
  drop emailVerified/name; make userId nullable
- CatalogItem: TEXT id → INTEGER id + TEXT uid PK; restructure FK columns
- Company: TEXT id → INTEGER id + TEXT uid PK; drop old CW columns; add
  dateDeleted/deleteFlag/phone/taxExempt/taxId/website/enteredById
- Opportunity: TEXT id → INTEGER id + TEXT uid PK; drop ~25 flat CW
  columns; add typeId/statusId/contactId/siteId/locationId/departmentId/
  closedById/primarySalesRepId/secondarySalesRepId/eneteredBy/updatedBy/
  oppNarrative/taxCodeId/interest; drop cwDateEntered
- UnifiSite: companyId TEXT → INTEGER
- 20+ new tables: CorporateLocation, InternalDepartment, CompanyAddress,
  Contact, CatalogItemType, CatalogCategory, CatalogSubcategory,
  CatalogManufacturer, Warehouse, WarehouseBin, ProductInventory,
  MinimumStockByWarehouse, ProductData, ServiceTicket, ServiceTicketNote,
  ServiceTicketType, ServiceTicketBoard, ServiceTicketLocation,
  ServiceTicketSource, ServiceTicketImpact, ServiceTicketPriority,
  ServiceTicketServerity, ServiceTicketFinalData, OpportunityType,
  OpportunityStatus, ScheduleStatus, ScheduleType, ScheduleSpan,
  Schedule, TaxCode

Verified: all 16 migrations apply cleanly on a fresh DB and produce zero
schema drift (prisma migrate diff outputs '-- This is an empty migration.')

Fixes P2022 ColumnNotFound errors on login and all model queries.
2026-04-08 13:40:29 +00:00
HoloPanio 7914c025a1 chore(migrate): add local migration test harness script 2026-04-08 05:36:41 +00:00
HoloPanio 8c32b0c5e0 fix(migrate): rewrite entrypoint to resolve P3009 from deploy error output v0.1.0-b1 2026-04-08 05:25:37 +00:00
HoloPanio f34178978e fix(ci): fix migration pod log retrieval 2026-04-08 05:13:14 +00:00
HoloPanio 9a1a641e97 fix(ci): don't hang forever waiting for migration job to complete 2026-04-08 05:05:40 +00:00
HoloPanio 557e729ca9 fix(ci): fix UI server build context, macOS/Windows desktop build steps 2026-04-08 04:56:17 +00:00
HoloPanio f3a8a7e25a ci: attempt to fix Deployment 2026-04-08 04:41:53 +00:00
HoloPanio b9c2ddb38b fix: add missing patches COPY + workspace COPY to Dockerfiles; fix UI workdir; add @prisma/client-runtime-utils explicitly to api and dalpuri 2026-04-08 04:18:17 +00:00
HoloPanio ee0434fa08 fix: add missing workspace package.json COPYs to Dockerfiles for bun workspace resolution 2026-04-08 03:51:19 +00:00
HoloPanio 7cbc0c9178 fix: pin bun to 1.3.11 in Dockerfiles, fix husky CI crash, fix workspace:* npm compat 2026-04-08 03:43:52 +00:00
HoloPanio 92318608dd fix(tests): mock workert module in setup to prevent PgBoss crash on missing DATABASE_URL 2026-04-08 03:22:57 +00:00
HoloPanio 8e5c0801ef fix: add missing socket.io-client dependency to api package 2026-04-08 03:18:40 +00:00
HoloPanio 0844fd0577 fix: remove dotenv/config import from prisma configs (not installed, Bun loads .env natively) 2026-04-08 03:11:44 +00:00
HoloPanio 1d48a2fe7b ci(global): fix failing tests 2026-04-08 03:09:27 +00:00
HoloPanio 43a3968788 fix: remove duplicate typescript and stale next dep from root package.json 2026-04-08 03:07:53 +00:00
HoloPanio e88d21fa35 ci(global): go through and make sure all related files are working and good to go 2026-04-08 03:04:58 +00:00
HoloPanio 546bf65b8b test(ui): i corrected UI Testing 2026-04-08 01:45:12 +00:00
HoloPanio 5d378ccb56 fix tests 2026-04-08 01:02:45 +00:00
HoloPanio 24f303355b all the haul 2026-04-07 23:56:31 +00:00
HoloPanio 87cce83030 fix(dalpuri): correct UTC timestamp field names in smart sync
Fixed field name mismatches for tables with lastUpdatedUTC (all-caps):
- IV_Product: lastUpdateUtc → lastUpdatedUTC
- Department: lastUpdateUtc → lastUpdatedUTC

These field names must match the Prisma schema exactly (case-sensitive).
Ensures smart sync decision logic can correctly probe for record updates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-01 21:28:22 -05:00
HoloPanio 688a9096c2 refactor(api): started implementing all of the tables needed for full data synchronization
BREAKING CHANGE: refer to body
2026-03-22 20:48:29 -05:00
HoloPanio 6b7eec67b8 fix: remove nested .git folders, re-add as normal directories 2026-03-22 17:50:47 -05:00
HoloPanio f55c7e47c9 chore:update everything 2026-03-22 17:47:03 -05:00
HoloPanio cb71133186 chore: add EVERYTHING 2026-03-22 17:44:44 -05:00
HoloPanio 91fa272fe6 chore: add EVERYTHING 2026-03-22 17:43:55 -05:00
HoloPanio 5ea7bb8f95 chore: import history from ui 2026-03-22 17:43:23 -05:00
HoloPanio 9fed61de68 chore: import history from api 2026-03-22 17:41:40 -05:00
Jackson ec4c8da786 Initial commit 2026-03-22 17:21:08 -05:00
HoloPanio 2f17f24b3b fix: ship sales tax rates with production runtime v0.1.23 2026-03-16 11:25:12 -05:00
HoloPanio 1230dacfa2 build: include logo.png in runtime image v0.1.22 2026-03-15 23:55:46 -05:00
HoloPanio 005e939a54 Swap Quick Add and Add to Cart button order in detail pane
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-15 23:53:41 -05:00
HoloPanio 85fa991c30 Sales opportunity enhancements and unsaved changes guard
- Add unsaved changes guard (UnsavedChangesDialog, EditGuard, dirtyState store)
- Add Breadcrumb component
- Add EmailText component
- Update sales opportunity detail with new tabs and workflow
- Add dashboard tab to sales page with metrics
- Update opportunity API URLs to include /opportunity/ path segment
- Add auth token refresh endpoint
- Add credential-types API endpoint
- Add CW members store
- Add sales-utils helpers
- Update layout server to return user info alongside canViewAdmin
- Fix unit tests to match updated API paths and return shapes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-15 23:43:34 -05:00
HoloPanio 1dc3c7ce07 test: align review approval status with ReadyToSend v0.1.21 2026-03-15 23:43:16 -05:00
HoloPanio e764932c39 feat: expand sales opportunity workflow and metrics APIs v0.1.20 2026-03-15 23:38:56 -05:00
HoloPanio e74611cd96 refactor: extract reusable UI components and shared utilities 2026-03-12 22:47:06 -05:00
HoloPanio 33b34d08a7 Add migration for CwMember table
Creates the CwMember table migration that was missing from the migration history
(previously applied locally via db push but never migrated for production).
v0.1.19
2026-03-09 17:59:17 -05:00
HoloPanio 7ffbd98f2e feat: add taxableFlag editing and improve add-products UX
- Make taxableFlag editable in opportunity product detail view
- Normalize salesTaxable → taxableFlag in procurement catalog API
- Add taxableFlag to EditOpportunityProductBody interface
- Add loading spinner and disable button during 'Add Selected Items'
- Prevent double-submit on add-selected-items action
2026-03-09 17:49:28 -05:00
HoloPanio 5afda8cb34 Add taxableFlag to product updates, QUO-Narrative quote fallback, and orphan reconciliation
- Add taxableFlag boolean field to product update schema and forecast patch
- Fall back to QUO-Narrative product customerDescription for quote narrative
- Reconcile orphaned local opportunity records not found in CW during refresh
- Invalidate caches for removed orphaned opportunities
- Add reconciled event and orphanedCount to refresh events
- Update API_ROUTES.md with taxableFlag field documentation
v0.1.18
2026-03-09 17:48:47 -05:00
HoloPanio ee3e0a7377 bypass checkColdStatus — always returns not-cold until feature ready v0.1.17 2026-03-09 03:33:59 -05:00
HoloPanio e294791858 fix: provide real checkColdStatus in wfOpportunity mock, remove stray closing brace 2026-03-09 03:29:00 -05:00
HoloPanio 97ac4a2173 fix: eliminate cross-file mock.module pollution — complete exports for all mocked modules 2026-03-09 03:26:22 -05:00
HoloPanio ad7507d133 fix: use real cache key prefixes in mock and dynamic imports for CI compatibility 2026-03-09 03:08:15 -05:00
HoloPanio 15ef24eb3e fix: resolve CI test failures — explicit cache mock exports, hoisted service mocks, pinned Bun 1.3.6 2026-03-09 03:03:06 -05:00
HoloPanio f53b390e18 feat: add opportunity workflows, delete routes, company sites, algorithms, and expanded test coverage 2026-03-09 02:56:08 -05:00