Sedifex Docs
Public catalog backfill (publicProducts / publicServices)
Use this when older products documents were created before the syncPublicProducts trigger existed (or before itemType routing was added), and you need to populate:
Public catalog backfill (publicProducts / publicServices)#
Use this when older products documents were created before the syncPublicProducts trigger existed (or before itemType routing was added), and you need to populate:
publicProductspublicServices
Prerequisites#
- Firebase Admin credentials available in your shell (
GOOGLE_APPLICATION_CREDENTIALS), or run in an environment wherefirebase-admincan authenticate. - Install functions dependencies:
cd functions
npm ci
Run backfill#
From repo root:
npm --prefix functions run backfill-public-catalog
The script will:
- Read docs from
products. - Write each record into:
publicServiceswhenitemType === "service"publicProductsfor all other item types (product,made_to_order, missing/unknown)
- Remove the same doc id from the opposite collection.
- Backfill missing
publishedAtvalues in both public collections.
Run for one store only#
You can scope by storeId in two equivalent ways:
npm --prefix functions run backfill-public-catalog -- --store-id=YOUR_STORE_ID
or:
node functions/scripts/backfillPublicProducts.js YOUR_STORE_ID
Verify after backfill#
Quick counts in Firestore console:
productsfor a storepublicProductsfor same storepublicServicesfor same store
Then verify a few sample product IDs:
- A
serviceitem should only exist inpublicServices/<productId>. - A non-service item should only exist in
publicProducts/<productId>.
Reconciliation mode (verify + repair)#
Run reconciliation when you want to actively check for drift and repair it:
npm --prefix functions run backfill-public-catalog -- --mode=reconcile
Single-store reconciliation:
npm --prefix functions run backfill-public-catalog -- --mode=reconcile --store-id=YOUR_STORE_ID
Reconciliation validates published products/<id> documents map to exactly one target (publicProducts or publicServices), then repairs:
- wrong-collection drift after
itemTypechanges, - missing
publishedAt/updatedAt, - non-normalized
categoryvalues (trimmed, single-spaced, lowercase), - orphan public docs with no matching published source product.
It also emits a per-store summary report and refreshes store health fields:
publicCatalogLastSyncedAtpublicCatalogDocCount.productspublicCatalogDocCount.servicespublicCatalogOutOfSyncCount