transceiver-db/sql/112-migrate-wavelengths-text-to-int.sql
Rene Fichtmueller 9979b79434 feat: wavelength/connector enrichment schema + enricher robot
- sql/110: add wavelength_tx_nm, wavelength_rx_nm, connector_type,
  data_completeness, enrichment_needed columns + trigger
- sql/111: IEEE/MSA standards wavelength lookup table (SFP→OSFP)
- sql/112: migrate existing wavelengths TEXT → integer columns
- robots/wavelength-enricher.ts: fills missing wavelengths from IEEE
  lookup (deterministic) then product-name regex, runs every 4h
- scheduler: register enrich:wavelength job (4h schedule)

Fixes over-broad matching where 1G SFPs match 500+ competitors
due to missing wavelength discrimination.
2026-05-13 17:35:42 +02:00

49 lines
1.6 KiB
SQL

-- Migration 112: wavelengths TEXT → wavelength_tx_nm / wavelength_rx_nm INTEGER
UPDATE transceivers SET
wavelength_tx_nm = CASE
WHEN wavelengths ~ '^\s*850' THEN 850
WHEN wavelengths ~ '^\s*1270' THEN 1270
WHEN wavelengths ~ '^\s*1310' THEN 1310
WHEN wavelengths ~ '^\s*1330' THEN 1330
WHEN wavelengths ~ '^\s*1490' THEN 1490
WHEN wavelengths ~ '^\s*1550' THEN 1550
WHEN wavelengths ~ '^\s*1270\s*/\s*1330' THEN 1270
WHEN wavelengths ~ '^\s*1330\s*/\s*1270' THEN 1330
ELSE NULL
END,
wavelength_rx_nm = CASE
WHEN wavelengths ~ '1270\s*/\s*1330' THEN 1330
WHEN wavelengths ~ '1330\s*/\s*1270' THEN 1270
WHEN wavelengths ~ '1310\s*/\s*1550' THEN 1550
WHEN wavelengths ~ '1550\s*/\s*1310' THEN 1310
ELSE NULL
END
WHERE wavelengths IS NOT NULL
AND wavelength_tx_nm IS NULL;
-- Connector aus alter connector-Spalte übernehmen (falls vorhanden)
UPDATE transceivers SET
connector_type = CASE connector
WHEN 'LC' THEN 'LC'
WHEN 'SC' THEN 'SC'
WHEN 'MPO' THEN 'MPO-12'
WHEN 'MPO-12' THEN 'MPO-12'
WHEN 'MPO-16' THEN 'MPO-16'
WHEN 'RJ45' THEN 'RJ45'
ELSE connector
END
WHERE connector IS NOT NULL AND connector_type IS NULL;
-- Completeness neu berechnen nach Migration
UPDATE transceivers SET
data_completeness = calc_data_completeness(
form_factor, speed_gbps, fiber_type,
reach_meters, wavelength_tx_nm, connector_type
),
enrichment_needed = (
form_factor IS NULL OR speed_gbps IS NULL OR
fiber_type IS NULL OR reach_meters IS NULL OR
wavelength_tx_nm IS NULL OR connector_type IS NULL
);