django-schema-audit
A reusable Django app that automatically audits all PostgreSQL DDL schema changes — CREATE, ALTER, DROP, RENAME — using native PostgreSQL event triggers. Every structural change to your database is silently recorded with full context: who did it, when, and the exact SQL used.
Requirements
- Python >= 3.10
- Django >= 4.2
- PostgreSQL (required — uses PostgreSQL event triggers)
- psycopg2-binary >= 2.9
Installation — 4 Steps
Step 1 — Install the package
pip install django-schema-audit
Step 2 — Add to INSTALLED_APPS
# settings.py
INSTALLED_APPS = [
...
'django_schema_audit_app',
]
Step 3 — Run migrations (creates the audit table in your database)
python manage.py migrate
Step 4 — Attach the PostgreSQL event trigger
python manage.py attach_schema_audit
That's it. All DDL changes in your PostgreSQL database are now being recorded automatically.
Model — pg_schema_audit_log
The app creates a single table pg_schema_audit_log with the following fields:
| Field | Type | Description |
|---|---|---|
id |
BigAutoField | Auto-incrementing primary key |
event_time |
DateTimeField | Timestamp of when the DDL event occurred (auto-set) |
username |
CharField(150) | PostgreSQL user who executed the command |
command_tag |
CharField(100) | Type of DDL command e.g. CREATE TABLE, ALTER TABLE |
object_type |
CharField(100) | Type of object affected e.g. table, index, sequence |
schema_name |
CharField(100) | PostgreSQL schema where the change occurred e.g. public |
table_name |
CharField(255) | Full identity of the affected object |
ddl_command |
TextField | The complete DDL SQL statement that was executed |
Output — What Gets Recorded
Every time a DDL statement runs against your PostgreSQL database, a new row is inserted into pg_schema_audit_log. For example, running:
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
total NUMERIC
);
Produces a record like:
| Field | Value |
|---|---|
event_time |
2025-06-01 10:32:45 UTC |
username |
postgres |
command_tag |
CREATE TABLE |
object_type |
table |
schema_name |
public |
table_name |
public.orders |
ddl_command |
CREATE TABLE orders (id SERIAL PRIMARY KEY, …) |
You can browse all audit records directly in Django Admin under the Schema Audit section, with search by table name or DDL command, and sorted by most recent event.
Django Admin
The pg_schema_audit_log model is registered in Django Admin out of the box:
- Listed columns:
event_time,command_tag,object_type,table_name,username - Searchable by:
table_name,ddl_command - Default ordering: newest events first
License
MIT
Metadata
Release files for django-schema-audit 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_schema_audit-1.0.5.tar.gz | 5.5 kB | Without provenance | Details for django_schema_audit-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_schema_audit-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for django_schema_audit-1.0.5-py3-none-any.whl |
Total release size: 12.9 kB
Release files / django_schema_audit-1.0.5.tar.gz
| Download URL | django_schema_audit-1.0.5.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4016ee6b809ce6317eb1d35dbe0bedd94785ca45d48bc64885636024cc46b9d7
|
|
BLAKE2b-256 checksum How to use checksums |
af4ff867ff2f99672534fa72fc8de84cae6478519a7b4bf7590da7685aa23858
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Release files / django_schema_audit-1.0.5-py3-none-any.whl
| Download URL | django_schema_audit-1.0.5-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e69164d15e5312b780707236a0c11d666f09836d4e24ead1a73576fa8246df6
|
|
BLAKE2b-256 checksum How to use checksums |
beabe546f2fd19778cd15b5b310662c91e4b33b09b7c01e8b767b9fc233419b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Security for django-schema-audit 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.