-- Migration 003: audit_logs table (MariaDB / MySQL) -- Append-only audit trail for critical admin operations. CREATE TABLE IF NOT EXISTS audit_logs ( id CHAR(36) NOT NULL DEFAULT (UUID()) PRIMARY KEY, action VARCHAR(128) NOT NULL, actor_id CHAR(36) NULL, actor_ip VARCHAR(45) NULL, target TEXT NOT NULL DEFAULT '', metadata JSON NOT NULL DEFAULT (JSON_OBJECT()), created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ); CREATE INDEX IF NOT EXISTS audit_logs_actor_time_idx ON audit_logs (actor_id, created_at DESC); CREATE INDEX IF NOT EXISTS audit_logs_action_time_idx ON audit_logs (action, created_at DESC); CREATE INDEX IF NOT EXISTS audit_logs_time_idx ON audit_logs (created_at DESC);