guanghulab/persona-brain-db/schema/13-audit-log-user.sql

23 lines
1.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ============================================================
-- 表13audit_log_user审计日志 · 用户操作 · append-only
-- 用途:普通用户级别的操作审计
-- ============================================================
CREATE TABLE IF NOT EXISTS audit_log_user (
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
operation VARCHAR(64) NOT NULL,
actor_id VARCHAR(64) NOT NULL, -- 用户ID
target_type VARCHAR(32),
target_id VARCHAR(64),
details TEXT, -- JSON object
ip_address VARCHAR(45),
user_agent VARCHAR(256),
result VARCHAR(16) NOT NULL
CHECK (result IN ('success', 'failure', 'pending')),
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_alu_actor ON audit_log_user(actor_id);
CREATE INDEX IF NOT EXISTS idx_alu_operation ON audit_log_user(operation);
CREATE INDEX IF NOT EXISTS idx_alu_timestamp ON audit_log_user(timestamp);