- audit_log 查询去掉 detail->>'user_id' 回退分支 - login_detail 不再冗余写入 user_id 到 detail JSON - 迁移 SQL 去掉多余的 ALTER TABLE ADD COLUMN Made-with: Cursor
24 lines
561 B
Rust
24 lines
561 B
Rust
use anyhow::Result;
|
|
use sqlx::PgPool;
|
|
use uuid::Uuid;
|
|
|
|
use crate::models::AuditLogEntry;
|
|
|
|
pub async fn list_for_user(pool: &PgPool, user_id: Uuid, limit: i64) -> Result<Vec<AuditLogEntry>> {
|
|
let limit = limit.clamp(1, 200);
|
|
|
|
let rows = sqlx::query_as(
|
|
"SELECT id, user_id, action, namespace, kind, name, detail, actor, created_at \
|
|
FROM audit_log \
|
|
WHERE user_id = $1 \
|
|
ORDER BY created_at DESC, id DESC \
|
|
LIMIT $2",
|
|
)
|
|
.bind(user_id)
|
|
.bind(limit)
|
|
.fetch_all(pool)
|
|
.await?;
|
|
|
|
Ok(rows)
|
|
}
|