Automatic field-level audit trail for all SQLModel entities in simple_module apps. Every create / update / delete / soft-delete is captured in the audit_log_audit_entry table with the changed fields, the user who made the change, and the request correlation id — no instrumentation required in module code.
pip install simple_module_audit_logAdd simple_module_audit_log to your host's dependencies and the entry point will be discovered automatically.
- Two-phase capture (
before_flushsnapshots diffs,after_flush_postexecresolves DB-assigned primary keys) so integer-PK entities record the real id, not the empty string. AuditEntrySQLModel table with indexedentity_type,entity_id,user_id,created_atcolumns.GET /api/audit_log/REST endpoint withentity_type,entity_id,action,user_id,from_date,to_date, paging filters./admin/audit-logInertia browse page with the same filter set rendered as a table, gated by theaudit_log.viewpermission.- Opt-outs: set
__audit_exclude__ = Trueon a model to skip it entirely, or__audit_exclude_fields__ = {"password_hash"}to skip specific columns.AuditMixin/SoftDeleteMixinbookkeeping fields are excluded automatically. - Credential redaction: set
__audit_redact_fields__(or a__audit_redact_row__predicate) to keep a field in the diff with its values replaced by[redacted]; see the audit_log docs for details.
Install the module and grant the audit_log.view permission to your admin role. Audit entries appear automatically for every entity that does not opt out.
To exclude a sensitive column:
from typing import ClassVar
from sqlmodel import Field
from simple_module_db.base import create_module_base
from simple_module_db.mixins import AuditMixin
Base = create_module_base("auth")
class Credential(Base, AuditMixin, table=True):
__audit_exclude_fields__: ClassVar[set[str]] = {"password_hash"}
id: int | None = Field(default=None, primary_key=True)
user_id: str
password_hash: strTo opt a whole table out:
class Cache(Base, table=True):
__audit_exclude__ = True
...MIT