Commit Graph

20 Commits

Author SHA1 Message Date
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.
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.
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.
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 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 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 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 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 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 91fa272fe6 chore: add EVERYTHING 2026-03-22 17:43:55 -05:00