PostgreSQL Schema Audit For Django
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_schema_audit-1.0.5.tar.gz.
File metadata
- Download URL: django_schema_audit-1.0.5.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4016ee6b809ce6317eb1d35dbe0bedd94785ca45d48bc64885636024cc46b9d7
|
|
| MD5 |
c019d6a9c2bc6b15e722a4080390ce1e
|
|
| BLAKE2b-256 |
af4ff867ff2f99672534fa72fc8de84cae6478519a7b4bf7590da7685aa23858
|
File details
Details for the file django_schema_audit-1.0.5-py3-none-any.whl.
File metadata
- Download URL: django_schema_audit-1.0.5-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e69164d15e5312b780707236a0c11d666f09836d4e24ead1a73576fa8246df6
|
|
| MD5 |
2437e4bbe0204336a0ce9020cfcecb46
|
|
| BLAKE2b-256 |
beabe546f2fd19778cd15b5b310662c91e4b33b09b7c01e8b767b9fc233419b4
|