fix: change products.canonical_name to TEXT, trim whitespace on import

VARCHAR(255) was too narrow for some OpenFoodFacts product names.
Switching to TEXT removes the length constraint entirely.
Also trim whitespace from resolved canonical names during import.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-03-21 15:33:49 +02:00
parent 78f1c8bf76
commit 6af7d2fade
2 changed files with 3 additions and 3 deletions

View File

@@ -209,9 +209,9 @@ func run() error {
} }
// Resolve canonical name: prefer English, fall back to any language. // Resolve canonical name: prefer English, fall back to any language.
canonicalName := record.ProductNameEN canonicalName := strings.TrimSpace(record.ProductNameEN)
if canonicalName == "" { if canonicalName == "" {
canonicalName = record.ProductName canonicalName = strings.TrimSpace(record.ProductName)
} }
// Apply filter rules. // Apply filter rules.

View File

@@ -124,7 +124,7 @@ CREATE TABLE product_category_translations (
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
CREATE TABLE products ( CREATE TABLE products (
id UUID PRIMARY KEY DEFAULT uuid_generate_v7(), id UUID PRIMARY KEY DEFAULT uuid_generate_v7(),
canonical_name VARCHAR(255) NOT NULL, canonical_name TEXT NOT NULL,
category VARCHAR(50) REFERENCES product_categories(slug), category VARCHAR(50) REFERENCES product_categories(slug),
default_unit VARCHAR(20) REFERENCES units(code), default_unit VARCHAR(20) REFERENCES units(code),
barcode TEXT UNIQUE, barcode TEXT UNIQUE,