Files
llm-intelligence/scripts/catalog_verification_common.go

57 lines
1.3 KiB
Go
Raw Normal View History

//go:build llm_script
package main
import (
"database/sql"
"fmt"
"time"
_ "github.com/lib/pq"
)
type catalogVerificationRecord struct {
CatalogCode string
SourceURL string
SourceTitle string
PlanStatus string
Notes string
}
type catalogVerificationImportConfig struct {
URL string
Fixture string
DryRun bool
Timeout time.Duration
}
func upsertCatalogVerificationRecords(db *sql.DB, records []catalogVerificationRecord) error {
if len(records) == 0 {
return fmt.Errorf("catalog verification records are empty")
}
for _, record := range records {
result, err := db.Exec(
`UPDATE plan_catalog_inventory
SET source_url = $2,
source_title = $3,
plan_status = $4,
notes = $5,
last_checked_at = CURRENT_TIMESTAMP,
updated_at = CURRENT_TIMESTAMP
WHERE catalog_code = $1`,
record.CatalogCode, record.SourceURL, record.SourceTitle, record.PlanStatus, record.Notes,
)
if err != nil {
return fmt.Errorf("update plan_catalog_inventory %s: %w", record.CatalogCode, err)
}
rowsAffected, err := result.RowsAffected()
if err != nil {
return fmt.Errorf("rows affected for %s: %w", record.CatalogCode, err)
}
if rowsAffected == 0 {
return fmt.Errorf("catalog_code %s not found in plan_catalog_inventory", record.CatalogCode)
}
}
return nil
}