This commit is contained in:
2026-08-17 00:39:25 +02:00
parent 92f046b542
commit 93dc70123c
54 changed files with 25528 additions and 20666 deletions
+35 -11
View File
@@ -41,22 +41,46 @@ func EnsureCategoryAttributeLinks(ctx context.Context, pool *pgxpool.Pool, compa
}
// RepairCompanyCategoryEnhancePrompts is the company-scoped variant of
// RepairA1DemoCategoryEnhancePrompts: same repairedCategoryEnhancePromptMap
// (sl + "*" with CategoryEnhanceUserTemplate / {{attrs}}), applied to one company.
// Idempotent — already-OK categories count as already_ok, not updated.
// RepairA1DemoCategoryEnhancePrompts: loads wp_product_categories.sql when
// available (upload bytes, SEED_A1_WP_CATEGORIES / Downloads), else
// a1-category-prompts.json, splits legacy combined overlays into role sections,
// and force-applies WP dump matches. Falls back to CategoryEnhanceUserTemplate.
// Idempotent when unchanged.
func RepairCompanyCategoryEnhancePrompts(ctx context.Context, pool *pgxpool.Pool, companyID uuid.UUID) (updated, alreadyOK, emptySkipped int, err error) {
if pool == nil {
return 0, 0, 0, fmt.Errorf("nil pool")
}
want, err := repairedCategoryEnhancePromptMap()
res, err := RepairCompanyCategoryEnhancePromptsWithOptions(ctx, pool, companyID, RepairA1DemoOptions{})
if err != nil {
return 0, 0, 0, err
}
summary := &RepairCategoryEnhancePromptsResult{ByCompany: map[string]int{}}
if _, err := repairCompanyCategoryEnhancePrompts(ctx, pool, companyID, companyID.String(), want, false, summary); err != nil {
return 0, 0, 0, err
return res.Updated, res.AlreadyOK, res.EmptySkipped, nil
}
// RepairCompanyCategoryEnhancePromptsWithOptions applies category enhance prompt
// repair for one company. Pass WPCategoriesSQL to force-apply an uploaded dump
// (Admin Sync A1); empty opts keep auto-detect fallback.
func RepairCompanyCategoryEnhancePromptsWithOptions(ctx context.Context, pool *pgxpool.Pool, companyID uuid.UUID, opts RepairA1DemoOptions) (RepairCategoryEnhancePromptsResult, error) {
out := RepairCategoryEnhancePromptsResult{
ByCompany: map[string]int{},
}
return summary.Updated, summary.AlreadyOK, summary.EmptySkipped, nil
if pool == nil {
return out, fmt.Errorf("nil pool")
}
if len(opts.WPCategoriesSQL) > 0 {
if _, _, err := LoadWPCategoryPromptOverlaysFromBytes(opts.WPCategoriesSQL); err != nil {
return out, fmt.Errorf("wp_product_categories upload: %w", err)
}
}
seedByNorm, seedByUID, seedMeta := resolveCategoryPromptOverlays(opts)
out.SeedPath = seedMeta.Path
out.WPCategoriesPath = seedMeta.WPPath
out.SeedEntries = seedMeta.Entries
forceFromSeed := seedMeta.ForceFromSeed
if opts.ForceFromSeed != nil {
forceFromSeed = *opts.ForceFromSeed
}
if _, err := repairCompanyCategoryEnhancePrompts(ctx, pool, companyID, companyID.String(), seedByNorm, seedByUID, false, forceFromSeed, &out); err != nil {
return out, err
}
return out, nil
}
// ResolvePlatformDemoCompanyID finds the Platform Demo sandbox (never A1 cohort).