- Corrige l'erreur SQL 'Unknown column fk_operation in users' - L'opération active est récupérée depuis operations.chk_active = 1 - Jointure avec users pour filtrer par entité de l'admin créateur - Query: SELECT o.id FROM operations o INNER JOIN users u ON u.fk_entite = o.fk_entite WHERE u.id = ? AND o.chk_active = 1
58 lines
2.6 KiB
SQL
Executable File
58 lines
2.6 KiB
SQL
Executable File
-- ============================================================
|
|
-- 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
|
|
--
|
|
-- ============================================================
|