use serde_json::Value; use sqlx::PgPool; use uuid::Uuid; pub async fn log_audit( pool: &PgPool, project_id: Option, user_id: Option, user_email: Option, action: &str, entity_type: &str, entity_id: Uuid, old_values: Option, new_values: Option, ip: Option, ) { let res = sqlx::query( r#" INSERT INTO audit_logs (project_id, user_id, user_email, action, entity_type, entity_id, old_values, new_values, client_ip) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) "# ) .bind(project_id) .bind(user_id) .bind(user_email) .bind(action) .bind(entity_type) .bind(entity_id) .bind(old_values) .bind(new_values) .bind(ip) .execute(pool) .await; if let Err(e) = res { tracing::error!("Failed to write audit log: {}", e); } }