Files
geo/api/scripts/sql/create_event_stats_daily.sql
Pierre 232940b1eb feat: Version 3.6.2 - Correctifs tâches #17-20
- #17: Amélioration gestion des secteurs et statistiques
- #18: Optimisation services API et logs
- #19: Corrections Flutter widgets et repositories
- #20: Fix création passage - détection automatique ope_users.id vs users.id

Suppression dossier web/ (migration vers app Flutter)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 14:11:15 +01:00

58 lines
2.6 KiB
SQL

-- ============================================================
-- Table event_stats_daily - Statistiques d'événements agrégées
-- Version: 1.0
-- Date: 2025-12-22
-- ============================================================
--
-- Usage: Exécuter dans les 3 environnements (DEV, REC, PROD)
-- mysql -u user -p database < create_event_stats_daily.sql
--
-- Description:
-- Stocke les statistiques quotidiennes agrégées depuis les
-- fichiers JSONL (/logs/events/YYYY-MM-DD.jsonl)
-- Alimentée par le CRON aggregate_event_stats.php (1x/nuit)
--
-- ============================================================
CREATE TABLE IF NOT EXISTS event_stats_daily (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
-- Clés d'agrégation
stat_date DATE NOT NULL COMMENT 'Date des statistiques',
entity_id INT UNSIGNED NULL COMMENT 'ID entité (NULL = stats globales super-admin)',
event_type VARCHAR(50) NOT NULL COMMENT 'Type événement (login_success, passage_created, etc.)',
-- Compteurs
count INT UNSIGNED DEFAULT 0 COMMENT 'Nombre d\'occurrences',
sum_amount DECIMAL(12,2) DEFAULT 0.00 COMMENT 'Somme des montants (passages/paiements)',
unique_users INT UNSIGNED DEFAULT 0 COMMENT 'Nombre d\'utilisateurs distincts',
-- Métadonnées agrégées (JSON)
metadata JSON NULL COMMENT 'Données agrégées: top secteurs, erreurs fréquentes, etc.',
-- Timestamps
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-- Contraintes
UNIQUE KEY uk_date_entity_event (stat_date, entity_id, event_type),
INDEX idx_entity_date (entity_id, stat_date),
INDEX idx_date (stat_date),
INDEX idx_event_type (event_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
COMMENT='Statistiques quotidiennes agrégées des événements (EventLogService)';
-- ============================================================
-- Exemples de données attendues
-- ============================================================
--
-- | stat_date | entity_id | event_type | count | sum_amount | unique_users |
-- |------------|-----------|------------------|-------|------------|--------------|
-- | 2025-12-22 | 5 | login_success | 45 | 0.00 | 12 |
-- | 2025-12-22 | 5 | passage_created | 128 | 2450.00 | 8 |
-- | 2025-12-22 | 5 | stripe_payment_success | 12 | 890.00 | 6 |
-- | 2025-12-22 | NULL | login_success | 320 | 0.00 | 85 | <- Global
--
-- ============================================================