fix
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/billing"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/processing"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
@@ -34,30 +35,9 @@ type categoryBackfillResult struct {
|
||||
}
|
||||
|
||||
// backfillMappedCategoriesFromProcessed copies processed_products.category into
|
||||
// raw_products.mapped_data.category for A1 only. Legacy dumps store category on
|
||||
// processed rows (unique_id codes); feed mappings never mapped a category field,
|
||||
// so re-processing without this backfill yields Uncategorized / grey C coverage.
|
||||
// raw_products.mapped_data.category for A1 only. Delegates to processing.
|
||||
func backfillMappedCategoriesFromProcessed(ctx context.Context, pg *pgxpool.Pool, companyID uuid.UUID) (int64, error) {
|
||||
ct, err := pg.Exec(ctx, `
|
||||
UPDATE raw_products r
|
||||
SET mapped_data = jsonb_set(
|
||||
COALESCE(r.mapped_data, '{}'::jsonb),
|
||||
'{category}',
|
||||
to_jsonb(p.category),
|
||||
true
|
||||
),
|
||||
updated_at = now()
|
||||
FROM processed_products p
|
||||
WHERE p.raw_product_id = r.id
|
||||
AND p.company_id = $1
|
||||
AND r.company_id = $1
|
||||
AND COALESCE(NULLIF(trim(p.category), ''), '') <> ''
|
||||
AND lower(trim(p.category)) <> 'none'
|
||||
AND COALESCE(NULLIF(trim(r.mapped_data->>'category'), ''), '') = ''`, companyID)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("backfill mapped category: %w", err)
|
||||
}
|
||||
return ct.RowsAffected(), nil
|
||||
return processing.BackfillMappedCategoriesFromProcessed(ctx, pg, companyID)
|
||||
}
|
||||
|
||||
// backfillCategoriesFromMySQLDump streams dump processed_products for the A1
|
||||
|
||||
Reference in New Issue
Block a user