Repository navigation
fix(brands): keep brand setup working while 00379 isn't applied yet - #1778
Merged
Merged
Conversation
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
approved these changes
Oct 29, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
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
42703it reads the brand again withoutsite_type_source.site_typeitself 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
42703doesn't throw, andsiteTypestays null. - Any other error still throws, as before.
- With 00379 applied, the path is exactly as on main.
- On
applySiteTypeDetection.- A
42703on the brand read returns{ skipped: 'unavailable' }before any page fetch or AI call, so nothing is spent. - A
42703on the stamped update returns the same.
- A
- Callers.
POST /api/brands/:id/detect-site-typereturns{ siteType: null, skipped: 'unavailable' }.scripts/detect-site-types.jscounts it as skipped.- Neither treats it as an error.
- Only
42703is 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.jsandbrand-ecommerce.test.tspass. Webtsc, eslint and prettier pass on the touched files. The full web suite passes with this PR merged with main.
Follow-ups (not blocking)
- In
server/src/lib/site-type-detect.js, the newUNDEFINED_COLUMNconstant sits betweenapplySiteTypeDetection's JSDoc and the function. The function's doc comment now attaches to the constant instead. Moving the constant above the JSDoc fixes it. - Once every install has 00379, the fallback can go. It is only there for a deploy that runs ahead of its migration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Production safety fix. #1761 and #1767, merged today, read
brands.site_type_sourceand writesite_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:
markBrandAsEcommercethrows. Onboarding's competitor step calls it for every shop (await ecommerceSetup.currentbefore saving competitors), so setup fails with "Failed to save competitors".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":markBrandAsEcommercereads 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).applySiteTypeDetectionreturns{ 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 fixHow 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
yarn typecheckclean🤖 Generated with Claude Code