feat: add audit_log_user table [D109] Layer 3 user operation audit

This commit is contained in:
bingshuo 2026-05-21 17:43:42 +08:00
parent e25df5f519
commit 52ddf9384a

View File

@ -0,0 +1,22 @@
-- ============================================================
-- 表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);