audit_trail.tables¶
Core table definitions for the audit log.
Both tables are partitioned in PostgreSQL, so their primary keys include the partition keys and nothing has a foreign key to them:
audit_transaction:PARTITION BY RANGE (issued_at), one partition per month.audit_activity:PARTITION BY LIST (severity), and each severity partition is itselfPARTITION BY RANGE (created_at), one partition per month.
The partitions are not part of the metadata; audit_trail.migrations
creates the parents and severity partitions, audit_trail.maintenance the
monthly ones.
MAX_IDENTIFIER_LENGTH
module-attribute
¶
PostgreSQL's limit on identifier length in bytes; longer names are truncated.
IndexKey
module-attribute
¶
IndexKey = Literal[
"severity",
"actor",
"object",
"target",
"scope",
"transaction",
"correlation",
"changes_gin",
]
Key of one audit_activity index.
DEFAULT_INDEXES
module-attribute
¶
DEFAULT_INDEXES: frozenset[IndexKey] = frozenset(
{
"severity",
"actor",
"object",
"target",
"scope",
"transaction",
"correlation",
}
)
Keys of the audit_activity indexes created unless indexes says otherwise.
OPTIONAL_INDEXES
module-attribute
¶
Keys of the indexes that exist but are off by default.
ALL_INDEXES
module-attribute
¶
Every valid key for build_tables(indexes=...).
AuditTables
dataclass
¶
The audit tables and the metadata they are bound to.
Attributes:
| Name | Type | Description |
|---|---|---|
metadata |
MetaData
|
Metadata holding both tables and the activity indexes. |
transaction |
Table
|
The |
activity |
Table
|
The |
build_tables ¶
build_tables(
*,
schema: str = "audit",
transaction_table: str = "audit_transaction",
activity_table: str = "audit_activity",
indexes: Collection[str] | None = None,
) -> AuditTables
Build the audit tables in a new MetaData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
str
|
Schema holding the tables. |
'audit'
|
transaction_table
|
str
|
Name of the transaction (context) table. |
'audit_transaction'
|
activity_table
|
str
|
Name of the activity (event) table. |
'audit_activity'
|
indexes
|
Collection[str] | None
|
Keys of the |
None
|
Returns:
| Type | Description |
|---|---|
AuditTables
|
The tables and their metadata. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a name is empty or too long for PostgreSQL once a partition suffix is added, the table names are equal, or an index key is unknown. |
Source code in audit_trail/tables.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |