guanghulab/persona-brain-db/schema/12-audit-log-national.sql

25 lines
1.3 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.

-- ============================================================
-- 表12audit_log_national审计日志 · 国家操作 · append-only
-- 用途:国家系统级别的操作审计,完全透明,不可篡改
-- Hash chain每行包含上一行的checksum形成链式结构
-- ============================================================
CREATE TABLE IF NOT EXISTS audit_log_national (
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
operation VARCHAR(64) NOT NULL,
actor VARCHAR(64) NOT NULL,
target_type VARCHAR(32),
target_id VARCHAR(64),
details TEXT, -- JSON object
ip_address VARCHAR(45),
result VARCHAR(16) NOT NULL
CHECK (result IN ('success', 'failure', 'pending')),
checksum VARCHAR(128), -- hash chain for append-only integrity
prev_log_id INTEGER REFERENCES audit_log_national(log_id),
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_aln_operation ON audit_log_national(operation);
CREATE INDEX IF NOT EXISTS idx_aln_actor ON audit_log_national(actor);
CREATE INDEX IF NOT EXISTS idx_aln_timestamp ON audit_log_national(timestamp);