This commit is contained in:
2026-08-16 16:57:36 +02:00
parent 96f8c1115c
commit 532d439c41
106 changed files with 10147 additions and 494 deletions
+36
View File
@@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"github.com/descrybe/descrybe-v2/apps/api/internal/processing"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
@@ -48,6 +49,7 @@ func migrateCatalogAndFeeds(
migrateProcessedProducts(ctx, mysqlDB, pg, companyMap, feedMap, rawMap, allow, report, dryRun)
backfillProcessedDescriptionsFromMapped(ctx, pg, companyMap, allow, report, dryRun)
backfillProcessedNamesFromMapped(ctx, pg, companyMap, allow, report, dryRun)
backfillProcessedCategoriesFromMapped(ctx, pg, companyMap, allow, report, dryRun)
}
if domains.has("feeds") {
migrateExportFeeds(ctx, mysqlDB, pg, companyMap, feedMap, allow, report, dryRun)
@@ -956,6 +958,40 @@ func backfillProcessedNamesFromMapped(
}
}
// backfillProcessedCategoriesFromMapped fills empty processed.category from mapped unique_ids.
func backfillProcessedCategoriesFromMapped(
ctx context.Context,
pg *pgxpool.Pool,
companyMap map[string]string,
allow map[string]bool,
report map[string]int,
dryRun bool,
) {
if dryRun || pg == nil {
return
}
total := 0
for legacy, cid := range companyMap {
if len(allow) > 0 && !allow[legacy] {
continue
}
u, err := uuid.Parse(cid)
if err != nil {
continue
}
res, err := processing.BackfillProcessedCategoriesFromMapped(ctx, pg, u)
if err != nil {
log.Printf("processed category backfill company=%s: %v", cid, err)
continue
}
total += int(res.Updated)
}
if total > 0 {
report["processed_categories_backfilled"] = total
log.Printf("backfilled %d processed_products.category from mapped_data", total)
}
}
func migrateExportFeeds(
ctx context.Context,
mysqlDB *sql.DB,