addSql(<<<'SQL' CREATE TABLE audit_log ( id uuid NOT NULL, entity_type VARCHAR(100) NOT NULL, entity_id VARCHAR(64) NOT NULL, action VARCHAR(10) NOT NULL, changes JSONB NOT NULL DEFAULT '{}'::jsonb, performed_by VARCHAR(100) NOT NULL, performed_at TIMESTAMP(6) WITH TIME ZONE NOT NULL, ip_address VARCHAR(45) DEFAULT NULL, request_id VARCHAR(36) DEFAULT NULL, PRIMARY KEY(id) ) SQL); // Index pour recherche par entite (detail d'historique d'un objet). $this->addSql('CREATE INDEX idx_audit_entity_time ON audit_log (entity_type, entity_id, performed_at)'); // Index pour recherche par utilisateur (qui a fait quoi). $this->addSql('CREATE INDEX idx_audit_performer ON audit_log (performed_by, performed_at)'); // Index pour tri chronologique global (listing pagine DESC). $this->addSql('CREATE INDEX idx_audit_time ON audit_log (performed_at)'); } public function down(Schema $schema): void { $this->addSql('DROP TABLE audit_log'); } }