Skip to content

fix(brands): keep brand setup working while 00379 isn't applied yet - #1778

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/site-type-missing-column
Oct 29, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/site-type-missing-column

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Production safety fix. #1761 and #1767, merged today, read brands.site_type_source and write site_type_detected_at. Both columns come with migration 00379, which isn't applied on the dev database yet and may not be on production either.

If the code runs before that migration:

  • markBrandAsEcommerce throws. Onboarding's competitor step calls it for every shop (await ecommerceSetup.current before saving competitors), so setup fails with "Failed to save competitors".
  • Detection (POST /api/brands/:id/detect-site-type) errors. It runs in the background, so it is only noise.

Now: both treat Postgres' undefined-column error (42703) as "not yet":

  • markBrandAsEcommerce reads the brand again without the new column. Shopping mode, the industry and ChatGPT Shopping still go on, and the site type is left for detection once 00379 is applied (siteType: null).
  • applySiteTypeDetection returns { skipped: 'unavailable' } instead of throwing, both on the read and on the write.

Any other error still throws as before.

The real fix is applying 00379 on production. This only keeps setup working until then.

Related issue

None (production safety, follow-up to #1761 / #1767).

Type of change

  • fix — Bug fix

How to test

  • cd server && npx vitest run src/lib/site-type-detect.test.js (29 tests, incl. 42703 on the read and on the write).
  • cd web && yarn vitest run src/lib/actions/brand-ecommerce.test.ts (8 tests, incl. Shopping mode on with no type write when the column is missing).

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Server and web: related tests pass; prettier, eslint and yarn typecheck clean
  • Full suite and build: CI (urgent fix)

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 29, 2026 19:03
ansvisor#1761 and ansvisor#1767 read brands.site_type_source and write
site_type_detected_at (00379). If the code is deployed before the
migration, markBrandAsEcommerce threw during onboarding's competitor
step for any shop, and detection errored. Both now treat Postgres'
undefined-column error (42703) as 'not yet': Shopping mode still goes
on and the site type is left for detection once 00379 is applied.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Production already has 00379, so on prod this is a safety net only. I checked that it degrades safely if the code ever runs ahead of the migration (a fresh self-host, a staging database).

What I checked

  • markBrandAsEcommerce.
    • On 42703 it reads the brand again without site_type_source. site_type itself is older (00205), so the second read works on a pre-00379 schema.
    • It skips the site-type write, and Shopping mode still turns on.
    • An update that fails with 42703 doesn't throw, and siteType stays null.
    • Any other error still throws, as before.
    • With 00379 applied, the path is exactly as on main.
  • applySiteTypeDetection.
    • A 42703 on the brand read returns { skipped: 'unavailable' } before any page fetch or AI call, so nothing is spent.
    • A 42703 on the stamped update returns the same.
  • Callers.
    • POST /api/brands/:id/detect-site-type returns { siteType: null, skipped: 'unavailable' }.
    • scripts/detect-site-types.js counts it as skipped.
    • Neither treats it as an error.
  • Only 42703 is caught. A permission error or a missing row still surfaces.
  • Merges clean on current main. No migration, no embeds, and no new action or route.
  • Tests: site-type-detect.test.js and brand-ecommerce.test.ts pass. Web tsc, eslint and prettier pass on the touched files. The full web suite passes with this PR merged with main.

Follow-ups (not blocking)

  1. In server/src/lib/site-type-detect.js, the new UNDEFINED_COLUMN constant sits between applySiteTypeDetection's JSDoc and the function. The function's doc comment now attaches to the constant instead. Moving the constant above the JSDoc fixes it.
  2. Once every install has 00379, the fallback can go. It is only there for a deploy that runs ahead of its migration.

@gkhngyk
gkhngyk merged commit 5d913a6 into ansvisor:main Oct 29, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants