feat(catalog): supplier catalog cleanup, fuzzy matching, and navigation fixes
- Cleaned 137+ fake engine-displacement models from supplier imports (v3/v4 scripts: Chevrolet, Ford, Chrysler, Dodge, Jeep, Nissan, etc.) - Removed 1,251+ corrupted models (INT. prefixes, year-suffix, torque specs, empty names, trailing-year variants) - Migrated supplier tables to master DB (supplier_catalog, supplier_catalog_compat, supplier_catalog_interchange) - Fixed _get_mye_ids_with_parts() to query supplier_catalog_compat from master DB so supplier-only vehicles appear for all tenants - Added fuzzy model matcher with parenthesis stripping, noise suffix removal, compact matching, prefix/substring fallback, model aliases, and ±3 year proximity - Matched compat rows: KEEP GREEN +14,152, KNADIAN +3,021, VAZLO +127,500, LUK +477, RAYBESTOS +1,743 - Added KNADIAN catalog importer with year-range expansion and future-year filtering - Added VAZLO catalog importer with position parsing and SKU-in-model cleanup - Added Keep Green, LUK, Yokomitsu, Raybestos catalog importers - Cache clearing after cleanups (_classify_cache_*, nexus:mye_ids:*, nexus:brand_mye_counts:*) Final match rates: - KEEP GREEN: 90.3% - VAZLO: 93.6% - YOKOMITSU: 100.0% - KNADIAN: 57.4% - LUK: 51.0% - RAYBESTOS: 55.9%
This commit is contained in:
@@ -33,6 +33,7 @@ MIGRATIONS = {
|
||||
'v3.0': 'v3.0_public_api.sql',
|
||||
'v3.1': 'v3.1_inventory_vehicle_compat.sql',
|
||||
'v3.2': 'v3.2_db_performance.sql',
|
||||
'v3.8': 'v3.8_supplier_catalog.sql',
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -386,3 +386,4 @@ CREATE TABLE IF NOT EXISTS tenant_config (
|
||||
|
||||
-- Barcode sequence
|
||||
CREATE SEQUENCE IF NOT EXISTS barcode_seq START 1;
|
||||
|
||||
|
||||
30
pos/migrations/v3.5_meli_questions.sql
Normal file
30
pos/migrations/v3.5_meli_questions.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
-- ============================================================
|
||||
-- v3.5 MercadoLibre Questions & Answers
|
||||
-- ============================================================
|
||||
-- Adds table for tracking buyer questions on ML listings.
|
||||
-- All tables live in the tenant DB.
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS marketplace_questions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
listing_id INTEGER REFERENCES marketplace_listings(id) ON DELETE SET NULL,
|
||||
external_question_id VARCHAR(50) NOT NULL UNIQUE,
|
||||
external_item_id VARCHAR(50) NOT NULL,
|
||||
question_text TEXT NOT NULL,
|
||||
answer_text TEXT,
|
||||
status VARCHAR(20) DEFAULT 'unanswered', -- unanswered, answered, closed
|
||||
buyer_id VARCHAR(50),
|
||||
buyer_nickname VARCHAR(100),
|
||||
question_date TIMESTAMPTZ,
|
||||
answer_date TIMESTAMPTZ,
|
||||
raw_json JSONB,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_marketplace_questions_status
|
||||
ON marketplace_questions(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_marketplace_questions_listing
|
||||
ON marketplace_questions(listing_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_marketplace_questions_external
|
||||
ON marketplace_questions(external_question_id);
|
||||
18
pos/migrations/v3.6_dropshipping.sql
Normal file
18
pos/migrations/v3.6_dropshipping.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- ============================================================
|
||||
-- v3.6 Dropshipping API Integration
|
||||
-- ============================================================
|
||||
-- Adds config keys and webhook targets for external
|
||||
-- dropshipping platforms.
|
||||
-- ============================================================
|
||||
|
||||
-- Webhook targets for dropshipping notifications per tenant
|
||||
CREATE TABLE IF NOT EXISTS dropshipping_webhooks (
|
||||
id SERIAL PRIMARY KEY,
|
||||
event_type VARCHAR(30) NOT NULL, -- stock_updated, price_updated, sale_made
|
||||
target_url TEXT NOT NULL,
|
||||
is_active BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_dropshipping_webhooks_event
|
||||
ON dropshipping_webhooks(event_type) WHERE is_active = true;
|
||||
22
pos/migrations/v3.7_sku_aliases.sql
Normal file
22
pos/migrations/v3.7_sku_aliases.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- ============================================================
|
||||
-- v3.7 SKU Aliases (multiple SKUs per inventory item)
|
||||
-- ============================================================
|
||||
-- Allows registering 2-3 alternative part numbers/SKUs for the
|
||||
-- same product (e.g. different supplier SKUs).
|
||||
-- ============================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS inventory_sku_aliases (
|
||||
id SERIAL PRIMARY KEY,
|
||||
inventory_id INTEGER NOT NULL REFERENCES inventory(id) ON DELETE CASCADE,
|
||||
sku VARCHAR(100) NOT NULL,
|
||||
label VARCHAR(50), -- e.g. "Bodega A", "Proveedor X"
|
||||
is_active BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
CONSTRAINT inventory_sku_aliases_unique_sku
|
||||
UNIQUE (inventory_id, sku)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_inventory_sku_aliases_inventory
|
||||
ON inventory_sku_aliases(inventory_id) WHERE is_active = true;
|
||||
CREATE INDEX IF NOT EXISTS idx_inventory_sku_aliases_sku
|
||||
ON inventory_sku_aliases(sku) WHERE is_active = true;
|
||||
63
pos/migrations/v3.8_supplier_catalog.sql
Normal file
63
pos/migrations/v3.8_supplier_catalog.sql
Normal file
@@ -0,0 +1,63 @@
|
||||
-- v3.8 — Supplier Catalog tables
|
||||
-- Adds supplier_catalog, supplier_catalog_compat, and supplier_catalog_interchange
|
||||
-- to support multi-supplier parts injection into the vehicle catalog.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS supplier_catalog (
|
||||
id SERIAL PRIMARY KEY,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
supplier_name VARCHAR(255) NOT NULL,
|
||||
sku VARCHAR(255) NOT NULL,
|
||||
name VARCHAR(500) NOT NULL,
|
||||
category VARCHAR(255),
|
||||
description TEXT,
|
||||
image_url TEXT,
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS supplier_catalog_tenant_id_supplier_name_sku_category_key
|
||||
ON supplier_catalog (tenant_id, supplier_name, sku, category);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sc_supplier
|
||||
ON supplier_catalog (tenant_id, supplier_name, is_active);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sc_sku
|
||||
ON supplier_catalog (tenant_id, sku, category);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS supplier_catalog_compat (
|
||||
id SERIAL PRIMARY KEY,
|
||||
catalog_id INTEGER NOT NULL REFERENCES supplier_catalog(id) ON DELETE CASCADE,
|
||||
make VARCHAR(255),
|
||||
model VARCHAR(255),
|
||||
year INTEGER,
|
||||
engine VARCHAR(255),
|
||||
engine_code VARCHAR(255),
|
||||
model_year_engine_id INTEGER,
|
||||
source VARCHAR(50) DEFAULT 'import',
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS supplier_catalog_compat_catalog_id_make_model_year_engine_key
|
||||
ON supplier_catalog_compat (catalog_id, make, model, year, engine);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_scc_catalog
|
||||
ON supplier_catalog_compat (catalog_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_scc_vehicle
|
||||
ON supplier_catalog_compat (make, model, year);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_scc_mye
|
||||
ON supplier_catalog_compat (model_year_engine_id);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS supplier_catalog_interchange (
|
||||
id SERIAL PRIMARY KEY,
|
||||
catalog_id INTEGER NOT NULL REFERENCES supplier_catalog(id) ON DELETE CASCADE,
|
||||
brand VARCHAR(255),
|
||||
part_number VARCHAR(255),
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sci_catalog
|
||||
ON supplier_catalog_interchange (catalog_id);
|
||||
Reference in New Issue
Block a user