81 lines
4.2 KiB
SQL
81 lines
4.2 KiB
SQL
-- MSIN-4464 — Traçabilité fiches : config whitelist + rétention
|
||
-- Prérequis : aucun
|
||
-- Notes prod : idempotent (CREATE IF NOT EXISTS + seeds via NOT EXISTS)
|
||
|
||
SET NAMES utf8mb4;
|
||
|
||
/* Réglages globaux (1 seule ligne) */
|
||
CREATE TABLE IF NOT EXISTS `inscriptions_fiche_audit_settings` (
|
||
`setting_id` tinyint(3) unsigned NOT NULL DEFAULT 1,
|
||
`retention_days` smallint(5) unsigned NOT NULL DEFAULT 90
|
||
COMMENT 'MSIN-4464 — durée de conservation des entrées détaillées',
|
||
`retention_max_per_field` smallint(5) unsigned NOT NULL DEFAULT 10
|
||
COMMENT 'MSIN-4464 — max d''entrées gardées par champ × participant',
|
||
`track_last_touch` tinyint(1) unsigned NOT NULL DEFAULT 1
|
||
COMMENT 'MSIN-4464 — noter aussi qui a touché la fiche (sans détail de champ)',
|
||
`setting_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||
PRIMARY KEY (`setting_id`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||
COMMENT='MSIN-4464 — réglages traçabilité fiche';
|
||
|
||
INSERT INTO `inscriptions_fiche_audit_settings`
|
||
(`setting_id`, `retention_days`, `retention_max_per_field`, `track_last_touch`)
|
||
SELECT 1, 90, 10, 1
|
||
WHERE NOT EXISTS (
|
||
SELECT 1 FROM `inscriptions_fiche_audit_settings` WHERE `setting_id` = 1
|
||
);
|
||
|
||
/* Whitelist des champs à tracer en détail (old → new + auteur) */
|
||
CREATE TABLE IF NOT EXISTS `inscriptions_fiche_audit_fields` (
|
||
`field_key` varchar(64) NOT NULL,
|
||
`field_label_fr` varchar(100) NOT NULL,
|
||
`field_label_en` varchar(100) NOT NULL,
|
||
`field_actif` tinyint(1) unsigned NOT NULL DEFAULT 0,
|
||
`field_tri` smallint(5) unsigned NOT NULL DEFAULT 0,
|
||
`field_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||
PRIMARY KEY (`field_key`),
|
||
KEY `idx_faf_actif_tri` (`field_actif`, `field_tri`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||
COMMENT='MSIN-4464 — whitelist champs audités fiche';
|
||
|
||
INSERT INTO `inscriptions_fiche_audit_fields`
|
||
(`field_key`, `field_label_fr`, `field_label_en`, `field_actif`, `field_tri`)
|
||
SELECT 'par_statut_course', 'Statut de course', 'Race status', 1, 10
|
||
WHERE NOT EXISTS (SELECT 1 FROM `inscriptions_fiche_audit_fields` WHERE `field_key` = 'par_statut_course');
|
||
|
||
INSERT INTO `inscriptions_fiche_audit_fields`
|
||
(`field_key`, `field_label_fr`, `field_label_en`, `field_actif`, `field_tri`)
|
||
SELECT 'no_bib', 'Numéro de dossard', 'Bib number', 1, 20
|
||
WHERE NOT EXISTS (SELECT 1 FROM `inscriptions_fiche_audit_fields` WHERE `field_key` = 'no_bib');
|
||
|
||
INSERT INTO `inscriptions_fiche_audit_fields`
|
||
(`field_key`, `field_label_fr`, `field_label_en`, `field_actif`, `field_tri`)
|
||
SELECT 'no_bib_remis', 'Dossard remis', 'Bib handed out', 0, 30
|
||
WHERE NOT EXISTS (SELECT 1 FROM `inscriptions_fiche_audit_fields` WHERE `field_key` = 'no_bib_remis');
|
||
|
||
INSERT INTO `inscriptions_fiche_audit_fields`
|
||
(`field_key`, `field_label_fr`, `field_label_en`, `field_actif`, `field_tri`)
|
||
SELECT 'is_cancelled', 'Annulation', 'Cancellation', 0, 40
|
||
WHERE NOT EXISTS (SELECT 1 FROM `inscriptions_fiche_audit_fields` WHERE `field_key` = 'is_cancelled');
|
||
|
||
/* Journal détaillé — writers + UI « ? » dans une phase suivante */
|
||
CREATE TABLE IF NOT EXISTS `inscriptions_fiche_audit_log` (
|
||
`fal_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||
`par_id` int(10) unsigned NOT NULL,
|
||
`eve_id` int(10) unsigned DEFAULT NULL,
|
||
`field_key` varchar(64) NOT NULL
|
||
COMMENT 'champ whitelisté, ou last_touch pour intervention globale',
|
||
`old_value` varchar(255) DEFAULT NULL,
|
||
`new_value` varchar(255) DEFAULT NULL,
|
||
`changed_by_com_id` int(10) unsigned DEFAULT NULL,
|
||
`changed_by_label` varchar(120) DEFAULT NULL,
|
||
`source` varchar(32) DEFAULT NULL
|
||
COMMENT 'fiche, liste, mobile, system…',
|
||
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||
PRIMARY KEY (`fal_id`),
|
||
KEY `idx_fal_par_field_at` (`par_id`, `field_key`, `created_at`),
|
||
KEY `idx_fal_eve_at` (`eve_id`, `created_at`),
|
||
KEY `idx_fal_created` (`created_at`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||
COMMENT='MSIN-4464 — historique changements fiche (détail + last_touch)';
|