-- name: WriteAuditLog :exec INSERT INTO audit_log (actor_id, target_id, action, metadata) VALUES ($1, $2, $3, $4); -- name: ListAuditLog :many SELECT * FROM audit_log ORDER BY created_at DESC LIMIT $1 OFFSET $2; -- name: CountAuditLogByActions :one -- System actions carry no actor; system_only narrows to them. SELECT count(*)::bigint FROM audit_log WHERE action = ANY(sqlc.arg(actions)::text[]) AND (NOT sqlc.arg(system_only)::boolean OR actor_id IS NULL); -- name: ListAuditLogByActions :many -- One page of the given actions, newest first: the duplicates report's -- "resolved automatically" activity (M498) reads the resolver's merges and -- Lidarr release changes from here. SELECT * FROM audit_log WHERE action = ANY(sqlc.arg(actions)::text[]) AND (NOT sqlc.arg(system_only)::boolean OR actor_id IS NULL) ORDER BY created_at DESC, id LIMIT sqlc.arg(page_limit) OFFSET sqlc.arg(page_offset);