Pulls complete per-SKU specifications and compatibility data from the Flexoptix API (specifications=1&compatibilities=1) and writes structured fields to the transceivers table for datasheet generation. SQL migration 115: - Adds fx_specifications JSONB (raw spec blob for datasheet gen) - Adds fx_compatibilities JSONB (full OEM compatibility matrix) - Adds compliance_code, laser_type, receiver_type, supported_protocols[] - Adds extinction_ratio_db, cdr_support, inbuilt_fec, detail_synced_at - GIN index on fx_compatibilities for vendor/OPN queries flexoptix-detail-enricher.ts: - Per-SKU API calls with rate-limiting (600ms/call, 100 SKUs/run) - Parses all spec labels → structured fields (power, budget, tx/rx dBm, modulation, wavelengths, temp range, DOM, laser type, receiver type) - Strips :Sx variant suffixes before API queries (self-configure SKUs) - COALESCE writes — never overwrites existing data, only fills gaps - Tracks detail_synced_at, retries stale entries after 7 days flexoptix-api-sync.ts: - Also stores image_url and product_page_url during bulk sync scheduler.ts: - Registers enrich:flexoptix-details daily at 03:00 UTC Results after initial run: - 791/968 FX products (81.7%) fully enriched - 26.0 avg compatibility entries per product (OEM vendor + OPN) - 25.7 avg spec fields per product - DFB(483), EML(148), FP(72), VCSEL(44) laser type distribution
75 lines
3.6 KiB
SQL
75 lines
3.6 KiB
SQL
-- Migration 115: Flexoptix Product Detail Columns
|
|
-- Adds columns to store full product detail data from the Flexoptix API
|
|
-- (specifications array, compatibility matrix, laser type, receiver type, etc.)
|
|
-- so we can build rich datasheets and deepen the TIP comparison data.
|
|
|
|
-- ── New columns ──────────────────────────────────────────────────────────────
|
|
|
|
-- Raw specs blob: full [{label, value}, ...] array from API (specifications=1)
|
|
-- Useful for datasheet generation and ad-hoc queries without re-fetching
|
|
ALTER TABLE transceivers
|
|
ADD COLUMN IF NOT EXISTS fx_specifications JSONB;
|
|
|
|
-- Full compatibility list from API: [{sku, compatible_to_vendor, original_part_number}, ...]
|
|
-- More granular than vendor_compat (which has pattern-based matching)
|
|
ALTER TABLE transceivers
|
|
ADD COLUMN IF NOT EXISTS fx_compatibilities JSONB;
|
|
|
|
-- Structured spec fields parsed from fx_specifications
|
|
ALTER TABLE transceivers
|
|
ADD COLUMN IF NOT EXISTS compliance_code TEXT; -- "LX SGMII", "SR4 100GBASE", "LR4", etc.
|
|
|
|
ALTER TABLE transceivers
|
|
ADD COLUMN IF NOT EXISTS laser_type TEXT; -- "FP", "DFB", "VCSEL", "EML", "CW-SiPh"
|
|
|
|
ALTER TABLE transceivers
|
|
ADD COLUMN IF NOT EXISTS receiver_type TEXT; -- "PIN", "APD", "Coherent"
|
|
|
|
ALTER TABLE transceivers
|
|
ADD COLUMN IF NOT EXISTS supported_protocols TEXT[]; -- ["1GigE", "Fast Ethernet", "10GBase-SR", ...]
|
|
|
|
ALTER TABLE transceivers
|
|
ADD COLUMN IF NOT EXISTS extinction_ratio_db NUMERIC(6,2); -- dB
|
|
|
|
ALTER TABLE transceivers
|
|
ADD COLUMN IF NOT EXISTS cdr_support BOOLEAN; -- false = "none", true = integrated CDR
|
|
|
|
ALTER TABLE transceivers
|
|
ADD COLUMN IF NOT EXISTS inbuilt_fec BOOLEAN; -- false = "No", true = integrated FEC
|
|
|
|
-- Tracking: when the full per-SKU detail sync last completed for this product
|
|
ALTER TABLE transceivers
|
|
ADD COLUMN IF NOT EXISTS detail_synced_at TIMESTAMPTZ;
|
|
|
|
-- ── Indexes ──────────────────────────────────────────────────────────────────
|
|
|
|
-- GIN index for JSONB compatibility search (e.g. "which FX products are
|
|
-- compatible with Cisco Nexus 9000 where OPN starts with N9K-?")
|
|
CREATE INDEX IF NOT EXISTS idx_transceivers_fx_compatibilities
|
|
ON transceivers USING GIN (fx_compatibilities)
|
|
WHERE fx_compatibilities IS NOT NULL;
|
|
|
|
-- Index for detail sync queue (find unseen or stale products quickly)
|
|
-- NB: partial index with NOW() is not allowed (non-immutable); use plain index instead
|
|
CREATE INDEX IF NOT EXISTS idx_transceivers_detail_synced_at
|
|
ON transceivers (detail_synced_at NULLS FIRST);
|
|
|
|
-- ── Statistics ───────────────────────────────────────────────────────────────
|
|
DO $$
|
|
DECLARE
|
|
fx_cnt INTEGER;
|
|
BEGIN
|
|
SELECT COUNT(*) INTO fx_cnt
|
|
FROM transceivers t
|
|
JOIN vendors v ON v.id = t.vendor_id
|
|
WHERE UPPER(v.name) LIKE '%FLEXOPTIX%';
|
|
|
|
RAISE NOTICE 'Migration 115 complete.';
|
|
RAISE NOTICE ' Total FX products: %', fx_cnt;
|
|
RAISE NOTICE ' New columns added: fx_specifications, fx_compatibilities,';
|
|
RAISE NOTICE ' compliance_code, laser_type, receiver_type,';
|
|
RAISE NOTICE ' supported_protocols, extinction_ratio_db,';
|
|
RAISE NOTICE ' cdr_support, inbuilt_fec, detail_synced_at';
|
|
RAISE NOTICE ' Run enrich:flexoptix-details to populate.';
|
|
END $$;
|