patchcenter/migrate_pct_workflow_20260507.sql
Admin MPCZ 29f6153370 feat(pct): workflow prevenance PCT (auto-detection + gate confirmation + suffixe Teams)
- Migration migrate_pct_workflow_20260507.sql: ajoute patch_planning_import_rows
  pct_required (boolean default false), pct_confirmed_at (timestamptz),
  pct_confirmed_by_user_id (FK users). Backfill depuis servers.pct_required.
- Auto-detection a l'import (planning_import.py): scan referent_technique +
  mode_operatoire + impacts + commentaire pour pattern \bPCT\b mot entier
  (insensible casse) -> pct_required=true sur la row. Propage egalement vers
  servers.pct_required si pas deja true.
- UI iexec: badge orange '⚠ Prév PCT à faire' sur la cellule asset_name si
  pct_required=true et pas confirme, badge vert ' PCT ok' une fois confirme.
- Gate avant Step 3 (PATCH REEL): scan des serveurs cibles, si certains ont
  pct_required && !pct_confirmed -> 2 confirmations successives + appel
  POST /patching/iexec/confirm-pct qui marque pct_confirmed_at + user_id.
  Ne lance pas le patch si l'operateur annule.
- Endpoint POST /patching/iexec/confirm-pct: marque les rows comme PCT confirmes
  (pct_confirmed_at = now(), pct_confirmed_by_user_id = current user).
- Notif Teams: send_notification accepte planning_row_id optionnel ; si la row
  a pct_required && pct_confirmed, le message debut/fin est suffixe par
  ' (Prévenance PCT ok)' pour informer le responsable que l'amont a ete gere.
2026-05-07 08:19:19 +02:00

26 lines
1.3 KiB
SQL

-- Migration : workflow Prévenance PCT (gate confirmation + tracker)
-- - patch_planning_import_rows.pct_required : copie au moment de l'import (auto-détecté
-- à partir du contenu des colonnes texte référent_technique / mode_operatoire / impacts).
-- - patch_planning_import_rows.pct_confirmed_at : timestamp de confirmation par l'opérateur
-- avant le démarrage patching.
-- - patch_planning_import_rows.pct_confirmed_by_user_id : qui a confirmé.
-- - Backfill : pour les rows existantes, init pct_required depuis servers.pct_required.
-- Idempotent.
ALTER TABLE public.patch_planning_import_rows
ADD COLUMN IF NOT EXISTS pct_required boolean NOT NULL DEFAULT false,
ADD COLUMN IF NOT EXISTS pct_confirmed_at timestamptz,
ADD COLUMN IF NOT EXISTS pct_confirmed_by_user_id integer REFERENCES public.users(id) ON DELETE SET NULL;
-- Backfill : récupère pct_required du serveur lié pour les rows déjà importées
UPDATE public.patch_planning_import_rows r
SET pct_required = COALESCE(s.pct_required, false)
FROM public.servers s
WHERE r.server_id = s.id
AND r.pct_required = false
AND COALESCE(s.pct_required, false) = true;
CREATE INDEX IF NOT EXISTS idx_pp_rows_pct_pending
ON public.patch_planning_import_rows(pct_required)
WHERE pct_required = true AND pct_confirmed_at IS NULL;