Files
2026-08-16 18:36:56 +02:00

66 lines
2.4 KiB
Go

package main
import (
"context"
"io"
"log"
"github.com/descrybe/descrybe-v2/apps/api/internal/processing"
"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
}
// a1FixtureEANs aliases processing.A1FixtureEANs for seed-a1 tests.
var a1FixtureEANs = processing.A1FixtureEANs
func backfillMappedCategoriesFromProcessed(ctx context.Context, pg *pgxpool.Pool, companyID uuid.UUID) (int64, error) {
return processing.BackfillMappedCategoriesFromProcessed(ctx, pg, companyID)
}
func backfillCategoriesFromMySQLDump(ctx context.Context, pg *pgxpool.Pool, companyID uuid.UUID, dumpPath string) (categoryBackfillResult, error) {
res, err := processing.BackfillCategoriesFromMySQLDump(ctx, pg, companyID, dumpPath)
if err != nil {
return categoryBackfillResult{}, err
}
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
}
func purgeA1FixtureEANsFromOtherTenants(ctx context.Context, pg *pgxpool.Pool, a1CompanyID uuid.UUID) (rawN, ppN int64, err error) {
return processing.PurgeA1FixtureEANsFromOtherTenants(ctx, pg, a1CompanyID)
}
func scanA1ProcessedCategories(r io.Reader, legacyCompany string) (map[string]string, error) {
return processing.ScanA1ProcessedCategories(r, legacyCompany)
}
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)
}