2026-08-09 22:47:43 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"io"
|
|
|
|
|
"log"
|
|
|
|
|
|
2026-08-16 18:18:39 +02:00
|
|
|
"github.com/descrybe/descrybe-v2/apps/api/internal/processing"
|
2026-08-09 22:47:43 +02:00
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type categoryBackfillResult struct {
|
|
|
|
|
ProcessedUpdated int64
|
|
|
|
|
ProcessedInserted int64
|
|
|
|
|
MappedUpdated int64
|
|
|
|
|
DumpPairs int
|
|
|
|
|
PurgedOtherRaw int64
|
|
|
|
|
PurgedOtherPP int64
|
|
|
|
|
ProcessedWithCat int
|
|
|
|
|
ProcessedWithoutCat int
|
|
|
|
|
MappedWithCat int
|
|
|
|
|
MappedWithoutCat int
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-16 18:36:56 +02:00
|
|
|
// a1FixtureEANs aliases processing.A1FixtureEANs for seed-a1 tests.
|
|
|
|
|
var a1FixtureEANs = processing.A1FixtureEANs
|
|
|
|
|
|
2026-08-09 22:47:43 +02:00
|
|
|
func backfillMappedCategoriesFromProcessed(ctx context.Context, pg *pgxpool.Pool, companyID uuid.UUID) (int64, error) {
|
2026-08-16 18:18:39 +02:00
|
|
|
return processing.BackfillMappedCategoriesFromProcessed(ctx, pg, companyID)
|
2026-08-09 22:47:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func backfillCategoriesFromMySQLDump(ctx context.Context, pg *pgxpool.Pool, companyID uuid.UUID, dumpPath string) (categoryBackfillResult, error) {
|
2026-08-16 18:36:56 +02:00
|
|
|
res, err := processing.BackfillCategoriesFromMySQLDump(ctx, pg, companyID, dumpPath)
|
2026-08-09 22:47:43 +02:00
|
|
|
if err != nil {
|
2026-08-16 18:36:56 +02:00
|
|
|
return categoryBackfillResult{}, err
|
2026-08-09 22:47:43 +02:00
|
|
|
}
|
2026-08-16 18:36:56 +02:00
|
|
|
return categoryBackfillResult{
|
|
|
|
|
ProcessedUpdated: res.ProcessedUpdated,
|
|
|
|
|
ProcessedInserted: res.ProcessedInserted,
|
|
|
|
|
MappedUpdated: res.MappedUpdated,
|
|
|
|
|
DumpPairs: res.DumpPairs,
|
|
|
|
|
PurgedOtherRaw: res.PurgedOtherRaw,
|
|
|
|
|
PurgedOtherPP: res.PurgedOtherPP,
|
|
|
|
|
ProcessedWithCat: res.ProcessedWithCat,
|
|
|
|
|
ProcessedWithoutCat: res.ProcessedWithoutCat,
|
|
|
|
|
MappedWithCat: res.MappedWithCat,
|
|
|
|
|
MappedWithoutCat: res.MappedWithoutCat,
|
|
|
|
|
}, nil
|
2026-08-09 22:47:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func purgeA1FixtureEANsFromOtherTenants(ctx context.Context, pg *pgxpool.Pool, a1CompanyID uuid.UUID) (rawN, ppN int64, err error) {
|
2026-08-16 18:36:56 +02:00
|
|
|
return processing.PurgeA1FixtureEANsFromOtherTenants(ctx, pg, a1CompanyID)
|
2026-08-09 22:47:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func scanA1ProcessedCategories(r io.Reader, legacyCompany string) (map[string]string, error) {
|
2026-08-16 18:36:56 +02:00
|
|
|
return processing.ScanA1ProcessedCategories(r, legacyCompany)
|
2026-08-09 22:47:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func logCategoryBackfillResult(res categoryBackfillResult, source string) {
|
|
|
|
|
log.Printf("category backfill (%s): dump_pairs=%d processed_updated=%d processed_inserted=%d mapped_updated=%d purged_other_raw=%d purged_other_pp=%d",
|
|
|
|
|
source, res.DumpPairs, res.ProcessedUpdated, res.ProcessedInserted, res.MappedUpdated, res.PurgedOtherRaw, res.PurgedOtherPP)
|
|
|
|
|
log.Printf("A1 coverage: processed with_cat=%d without_cat=%d | raw mapped with_cat=%d without_cat=%d",
|
|
|
|
|
res.ProcessedWithCat, res.ProcessedWithoutCat, res.MappedWithCat, res.MappedWithoutCat)
|
|
|
|
|
}
|