[FEAT] A4 Fasi 4.4 + 4.5 (A4 COMPLETA 5/5): scadenziario centralizzato review_schedule (mig.044; ReviewScheduleController list/create/update/delete/complete/sync) + stakeholder estesi clienti/partner GV.SC-02 (mig.045 suppliers.stakeholder_type, SupplyChainController::stakeholderMap). Pagine review-schedule.html + stakeholders.html (Bootstrap Italia/AGID). Workflow build+review adversariale (3 major risolti: 045 da DELIMITER -> ALTER bare runner-safe). help GV.SC-04/05 allineati al titolo canonico ACN. Cache-buster ?v=20260620.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
c7d36c910f
commit
c5b00ccd96
+78
-7
@@ -8,23 +8,70 @@
|
||||
* USO (sull'host, con la connessione dell'app):
|
||||
* docker exec nis2-app php /var/www/nis2-agile/scripts/migrate-a4.php
|
||||
*
|
||||
* Idempotente: le migrazioni usano CREATE TABLE IF NOT EXISTS.
|
||||
* Sola lettura/additivo su tabelle esistenti: NON modifica nessuna tabella
|
||||
* preesistente. Stesso pattern di scripts/migrate-isms.php.
|
||||
* Idempotente: le migrazioni 041-044 usano CREATE TABLE IF NOT EXISTS; la 045
|
||||
* usa ALTER TABLE nude (MySQL 8 non ha ADD COLUMN/INDEX IF NOT EXISTS) e
|
||||
* l'idempotenza la garantisce shouldSkipAlter() con pre-check su
|
||||
* information_schema (stesso pattern di mig.040_onboarding_classification.sql).
|
||||
* Tutti i file SQL restano RUNNER-SAFE: solo statement nudi, niente DELIMITER /
|
||||
* stored procedure, nessun ';' dentro commenti o stringhe (lo split avviene su ';').
|
||||
* Stesso pattern di scripts/migrate-isms.php.
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../application/config/config.php';
|
||||
require_once __DIR__ . '/../application/config/database.php';
|
||||
|
||||
$files = [
|
||||
__DIR__ . '/../docs/sql/041_org_roles.sql', // Fase 4.1 — organigramma
|
||||
__DIR__ . '/../docs/sql/042_competences.sql', // Fase 4.2 — competenze
|
||||
// Le fasi 4.3-4.5 aggiungeranno qui i rispettivi file (043, ...).
|
||||
__DIR__ . '/../docs/sql/041_org_roles.sql', // Fase 4.1 — organigramma
|
||||
__DIR__ . '/../docs/sql/042_competences.sql', // Fase 4.2 — competenze
|
||||
__DIR__ . '/../docs/sql/043_raci.sql', // Fase 4.3 — matrice RACI + link m2m
|
||||
__DIR__ . '/../docs/sql/044_review_schedule.sql', // Fase 4.4 — scadenziario revisioni
|
||||
__DIR__ . '/../docs/sql/045_stakeholders.sql', // Fase 4.5 — stakeholder estesi (ALTER suppliers)
|
||||
];
|
||||
|
||||
$pdo = Database::getInstance();
|
||||
$totalStmts = 0;
|
||||
|
||||
/**
|
||||
* Pre-check di idempotenza per gli statement ALTER non nativamente idempotenti su
|
||||
* MySQL 8 (che NON supporta ADD COLUMN/INDEX IF NOT EXISTS). Ritorna true se lo
|
||||
* statement va SALTATO perche' la colonna/indice esiste gia'. Stesso pattern di
|
||||
* mig.040_onboarding_classification.sql: il .sql resta con statement nudi
|
||||
* (runner-safe, niente DELIMITER) e l'idempotenza la garantisce qui il runner.
|
||||
*/
|
||||
function shouldSkipAlter(PDO $pdo, string $stmt): bool {
|
||||
// ADD COLUMN <name>
|
||||
if (preg_match('/^ALTER\s+TABLE\s+`?(\w+)`?\s+ADD\s+COLUMN\s+`?(\w+)`?/i', $stmt, $m)) {
|
||||
$table = $m[1];
|
||||
$col = $m[2];
|
||||
$st = $pdo->prepare(
|
||||
'SELECT 1 FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?'
|
||||
);
|
||||
$st->execute([$table, $col]);
|
||||
if ($st->fetchColumn()) {
|
||||
echo " [skip] colonna gia presente: {$table}.{$col}\n";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// ADD INDEX <name>
|
||||
if (preg_match('/^ALTER\s+TABLE\s+`?(\w+)`?\s+ADD\s+(?:INDEX|KEY)\s+`?(\w+)`?/i', $stmt, $m)) {
|
||||
$table = $m[1];
|
||||
$idx = $m[2];
|
||||
$st = $pdo->prepare(
|
||||
'SELECT 1 FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND INDEX_NAME = ?'
|
||||
);
|
||||
$st->execute([$table, $idx]);
|
||||
if ($st->fetchColumn()) {
|
||||
echo " [skip] indice gia presente: {$table}.{$idx}\n";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (!is_readable($file)) {
|
||||
fwrite(STDERR, "[migrate-a4] File non leggibile: $file\n");
|
||||
@@ -48,11 +95,17 @@ foreach ($files as $file) {
|
||||
}
|
||||
$sql = implode("\n", $clean);
|
||||
|
||||
// Split semplice su ';' (nessun DELIMITER / stored procedure in questi file).
|
||||
// Split semplice su ';' (nessun DELIMITER / stored procedure in questi file:
|
||||
// 045 usa ALTER nude, l'idempotenza e' nel pre-check shouldSkipAlter()).
|
||||
$statements = array_filter(array_map('trim', explode(';', $sql)), fn($s) => $s !== '');
|
||||
|
||||
echo "== " . basename($file) . " (" . count($statements) . " statement) ==\n";
|
||||
foreach ($statements as $stmt) {
|
||||
// ALTER non nativamente idempotenti (es. mig.045 suppliers.stakeholder_type):
|
||||
// pre-check su information_schema, salta se colonna/indice gia presenti.
|
||||
if (shouldSkipAlter($pdo, $stmt)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$pdo->exec($stmt);
|
||||
$totalStmts++;
|
||||
@@ -85,3 +138,21 @@ foreach (['skills','role_skills','user_skills','skill_course_map'] as $t) {
|
||||
echo "[OK] $t pronta (" . count($c) . " colonne).\n";
|
||||
}
|
||||
echo "[OK] Competenze pronte (A4 Fase 4.2).\n";
|
||||
|
||||
// Verifica 4.3 (RACI + link m2m), 4.4 (scadenziario), 4.5 (stakeholder).
|
||||
foreach (['raci_assignments','procedure_inventory','procedure_risk','inventory_risk','risk_measure','review_schedule'] as $t) {
|
||||
$c = $pdo->query("SHOW COLUMNS FROM `$t`")->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
if (!$c) {
|
||||
fwrite(STDERR, "[ATTENZIONE] tabella mancante: $t\n");
|
||||
exit(1);
|
||||
}
|
||||
echo "[OK] $t pronta (" . count($c) . " colonne).\n";
|
||||
}
|
||||
echo "[OK] RACI + scadenziario pronti (A4 Fasi 4.3 e 4.4).\n";
|
||||
|
||||
$supCols = $pdo->query("SHOW COLUMNS FROM suppliers")->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
if (!in_array('stakeholder_type', $supCols, true)) {
|
||||
fwrite(STDERR, "[ATTENZIONE] suppliers.stakeholder_type mancante (A4 Fase 4.5)\n");
|
||||
exit(1);
|
||||
}
|
||||
echo "[OK] suppliers.stakeholder_type pronta (A4 Fase 4.5).\n";
|
||||
|
||||
Reference in New Issue
Block a user