Day 25: The Audit Trail and the Before and After Values of a Change
By the time someone asks who changed the amount on this record last month, it is usually months later. Whoever is asking has neither the screen as it looked then nor the build that was running, only the few rows left behind at the time. Who logged in, who changed which field from what to what, who looked at which record: every decision in the auditing layer has to assume that scene first,…
During the course of an audit, determining who made changes to a particular record is often a matter of looking back months later. The person inquiring will lack the initial screen appearance, build version, or specific details about the modification. Consequently, every logging aspect must account for this initial scenario, including those involving minimal actions akin to merely conserving storage space.
The article discusses three tables in the audit database that share common columns. The sole objective of these tables is to record three distinct questions. Each question corresponds to one table: where an event occurs, who initiated the action, and the outcome of the event.
The shared columns in all three tables include user ID, user name, company ID, company name, API key ID, API key name, and a trace ID. These columns are not normalized, meaning they are intentionally stored in a non-standardized format. This design decision allows for the preservation of historical information, such as a user's previous name or a company's former letterhead, even if those values differ from the current entries in the user or company tables.
Within the shared columns, the user ID serves as the primary identifier and can be directly linked to an audit row. However, sensitive information like passwords or API keys must remain protected. Therefore, the framework does not store such data in plain text, ensuring that only the user ID is recorded in the audit logs.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.