- Tables ENV_CANONICAL et DOMAIN_CANONICAL: lookup case+accent insensible - _canonicalize_env / _canonicalize_domain : retournent la forme canonique connue, sinon valeur d'origine inchangee - Applique dans l'INSERT row au moment de l'import - Lookup en 3 passes: 1. lowercase exact 2. lowercase + accents stripped 3. lowercase + accents + espaces normalises (ex 'Flux Libre' -> 'flux libre') Backfill SQL one-shot pour les rows existantes (backfill_canonicalize_env_domain_20260507.sql): - env: Production/Pré-Prod/Recette/Test/Test 1/Test 2/Développement/Qualif - domaine: Flux Libre/Péage/Infrastructure/Trafic/DMZ/LAN/BI/EMV/Gestion - Idempotent
71 lines
3.3 KiB
SQL
71 lines
3.3 KiB
SQL
-- One-shot : normalise les valeurs env/domaine existantes vers les formes canoniques
|
|
-- (cf table _canonicalize_env / _canonicalize_domain dans planning_import.py).
|
|
-- À jouer une fois après pull du code qui ajoute la canonicalisation à l'import.
|
|
-- Idempotent : on peut le rejouer sans effet de bord.
|
|
|
|
-- ─── Environnements ──────────────────────────────────────────
|
|
|
|
UPDATE patch_planning_import_rows SET environnement = 'Production'
|
|
WHERE LOWER(environnement) IN ('production','prod','prd')
|
|
AND environnement != 'Production';
|
|
|
|
UPDATE patch_planning_import_rows SET environnement = 'Pré-Prod'
|
|
WHERE LOWER(REGEXP_REPLACE(environnement, '\s+', ' ', 'g')) IN
|
|
('pré-prod','pre-prod','preprod','pre prod','pré prod',
|
|
'pre-production','pré-production','preproduction','préproduction')
|
|
AND environnement != 'Pré-Prod';
|
|
|
|
UPDATE patch_planning_import_rows SET environnement = 'Recette'
|
|
WHERE LOWER(environnement) IN ('recette','rec','recettes')
|
|
AND environnement != 'Recette';
|
|
|
|
UPDATE patch_planning_import_rows SET environnement = 'Test'
|
|
WHERE LOWER(environnement) IN ('test','tests')
|
|
AND environnement != 'Test';
|
|
|
|
UPDATE patch_planning_import_rows SET environnement = 'Test 1'
|
|
WHERE LOWER(REPLACE(REPLACE(environnement, '_', ' '), ' ', ' ')) IN ('test 1','test1')
|
|
AND environnement != 'Test 1';
|
|
|
|
UPDATE patch_planning_import_rows SET environnement = 'Test 2'
|
|
WHERE LOWER(REPLACE(REPLACE(environnement, '_', ' '), ' ', ' ')) IN ('test 2','test2')
|
|
AND environnement != 'Test 2';
|
|
|
|
UPDATE patch_planning_import_rows SET environnement = 'Développement'
|
|
WHERE LOWER(environnement) IN ('développement','developpement','dev','develop')
|
|
AND environnement != 'Développement';
|
|
|
|
UPDATE patch_planning_import_rows SET environnement = 'Qualif'
|
|
WHERE LOWER(environnement) IN ('qualif','qualification')
|
|
AND environnement != 'Qualif';
|
|
|
|
-- ─── Domaines ────────────────────────────────────────────────
|
|
|
|
UPDATE patch_planning_import_rows SET domaine = 'Flux Libre'
|
|
WHERE LOWER(REGEXP_REPLACE(domaine, '\s+', ' ', 'g')) IN ('flux libre','flux-libre','fluxlibre')
|
|
AND domaine != 'Flux Libre';
|
|
|
|
UPDATE patch_planning_import_rows SET domaine = 'Péage'
|
|
WHERE LOWER(domaine) IN ('peage','péage','peagé','pèage')
|
|
AND domaine != 'Péage';
|
|
|
|
UPDATE patch_planning_import_rows SET domaine = 'Infrastructure'
|
|
WHERE LOWER(domaine) IN ('infrastructure','infra')
|
|
AND domaine != 'Infrastructure';
|
|
|
|
UPDATE patch_planning_import_rows SET domaine = 'Trafic'
|
|
WHERE LOWER(domaine) IN ('trafic','traffic')
|
|
AND domaine != 'Trafic';
|
|
|
|
UPDATE patch_planning_import_rows SET domaine = UPPER(domaine)
|
|
WHERE LOWER(domaine) IN ('dmz','lan','bi','emv')
|
|
AND domaine != UPPER(domaine);
|
|
|
|
UPDATE patch_planning_import_rows SET domaine = 'Gestion'
|
|
WHERE LOWER(domaine) = 'gestion' AND domaine != 'Gestion';
|
|
|
|
-- ─── Vérification ───────────────────────────────────────────
|
|
|
|
-- SELECT environnement, COUNT(*) FROM patch_planning_import_rows GROUP BY 1 ORDER BY 1;
|
|
-- SELECT domaine, COUNT(*) FROM patch_planning_import_rows GROUP BY 1 ORDER BY 1;
|