mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
17 lines
750 B
SQL
17 lines
750 B
SQL
-- Migration 026: create audit_log table for data-level audit trail
|
|
-- Records before/after snapshots of every row mutation on core tables.
|
|
-- Admin actions are already logged separately via admin_audit_log.
|
|
CREATE TABLE IF NOT EXISTS audit_log (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
timestamp TEXT NOT NULL DEFAULT (datetime('now')),
|
|
actor TEXT NOT NULL,
|
|
action TEXT NOT NULL CHECK(action IN ('INSERT','UPDATE','DELETE')),
|
|
table_name TEXT NOT NULL,
|
|
record_id INTEGER,
|
|
old_data TEXT,
|
|
new_data TEXT
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_audit_log_table_record ON audit_log(table_name, record_id);
|
|
CREATE INDEX IF NOT EXISTS idx_audit_log_timestamp ON audit_log(timestamp);
|