8f4f59f0e3
[migration-approved]
Expert-driven workflow refinement on the Massnahmen page. The engine seeds
~80 mitigations per project, but for a concrete customer site most need a
relevance decision before they're meaningful in verification:
status: 'planned' | 'implemented' | 'verified' (existing — verification track)
is_relevant bool (new) (does this apply to *this* site?)
is_customer_standard bool (new) (already in place at customer — no evidence)
Decision flow on the Mitigations tab:
Engine-seeded → is_relevant=false (Default, waiting for expert)
Expert checks "Relevant" → is_relevant=true → surfaces in verification
Expert clicks trash → DELETE (banner warns: do not click Reinit
afterwards or seeds come back)
In verification, customer_standard=true bypasses evidence upload
is_customer_standard implies is_relevant (DB CHECK constraint).
Migration 029_iace_mitigation_relevance.sql:
ALTER TABLE iace_mitigations ADD COLUMN is_relevant ..., is_customer_standard ...
+ CHECK constraint + partial index on is_relevant for the verification
page's filter.
Backend (Go):
- Mitigation struct gains two bool fields
- CreateMitigation: defaults to false/false (engine-seeded mitigations
start unbewertet)
- UpdateMitigation: new case clauses for both keys; setting
is_customer_standard=true auto-flips is_relevant=true to satisfy
the CHECK constraint
- All three SELECT statements (ListMitigations, ListMitigationsByProject,
getMitigation) extended with the two new columns
Frontend:
- Maßnahmen-page columns: [Relev. ☑] [Lösch. 🗑] Title | #Hazards | P·I·V
- Group-header checkbox shows tri-state (indeterminate when partial),
flips all instances in the group at once
- Banner above the table: "Markiere jede Maßnahme als Relevant oder
lösche sie. Nach Löschen kein Neu initialisieren mehr drücken."
- Relevant rows tinted emerald, customer-standard label visible
- Legacy bulk-select state + helpers removed (the Relevant checkbox
now IS the primary mass action)
- useMitigations gains handleSetRelevant, handleSetCustomerStandard,
handleDeleteSilent (for non-confirm bulk deletes)
Future use: is_customer_standard mitigations from a prior project at the
same customer can later be auto-suggested when commissioning the next
plant — turning expert knowledge into reusable customer-profile data.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40 lines
2.1 KiB
SQL
40 lines
2.1 KiB
SQL
-- Migration 029: IACE Mitigation Relevance + Customer-Standard flag
|
|
-- ==========================================================================
|
|
-- The engine generates ~80 mitigations per project (Bremsscheibe benchmark).
|
|
-- Many are not applicable for a specific customer site — e.g. the customer
|
|
-- has 30 of them already implemented as company-wide standard. To keep the
|
|
-- verification step meaningful, the expert needs to:
|
|
--
|
|
-- 1. Mark each mitigation as relevant (or delete it from the project),
|
|
-- 2. Optionally flag it as "customer standard — no evidence required".
|
|
--
|
|
-- This is the difference between "applicable, must be verified" and
|
|
-- "applicable, but the expert already knows it's covered by the customer's
|
|
-- existing setup". Both must reach the verification report; only the first
|
|
-- needs an evidence upload.
|
|
--
|
|
-- A later feature reuses is_customer_standard to suggest pre-marked
|
|
-- mitigations when the same customer commissions another plant assessment.
|
|
-- ==========================================================================
|
|
|
|
-- is_relevant: Fachmann hat die Massnahme als anwendbar bestaetigt.
|
|
-- FALSE → Engine-Vorschlag, vom Fachmann noch nicht bewertet.
|
|
-- TRUE → Fachmann hat 'Relevant' angekreuzt; geht in die Verifikation.
|
|
-- is_customer_standard: Beim Kunden bereits implementiert.
|
|
-- FALSE → benötigt Nachweis in der Verifikation.
|
|
-- TRUE → keine Evidence-Datei notwendig; gilt als verifiziert.
|
|
ALTER TABLE iace_mitigations
|
|
ADD COLUMN IF NOT EXISTS is_relevant BOOLEAN NOT NULL DEFAULT FALSE,
|
|
ADD COLUMN IF NOT EXISTS is_customer_standard BOOLEAN NOT NULL DEFAULT FALSE;
|
|
|
|
-- An is_customer_standard mitigation is by definition relevant.
|
|
ALTER TABLE iace_mitigations
|
|
DROP CONSTRAINT IF EXISTS iace_mitigations_customer_standard_chk,
|
|
ADD CONSTRAINT iace_mitigations_customer_standard_chk
|
|
CHECK (is_customer_standard = FALSE OR is_relevant = TRUE);
|
|
|
|
-- Index for the verification-page filter (`WHERE is_relevant = TRUE`).
|
|
CREATE INDEX IF NOT EXISTS idx_iace_mitigations_relevant
|
|
ON iace_mitigations(is_relevant)
|
|
WHERE is_relevant = TRUE;
|