Implement historical tracking using django-pghistory; add middleware for context capture and update model architecture

This commit is contained in:
pacnpal
2025-02-08 21:18:44 -05:00
parent 71b73522ae
commit a148d34cf9
6 changed files with 223 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
## Model Migration Protocol for History Tracking
### Implementation Steps
1. **Base Model Setup**
```python
# core/models.py
import pghistory
class HistoricalModel(models.Model):
class Meta:
abstract = True
@pghistory.track(pghistory.Snapshot())
def save(self, *args, **kwargs):
return super().save(*args, **kwargs)
```
2. **Concrete Model Implementation**
```python
# parks/models.py
class Park(HistoricalModel):
@pghistory.track(
pghistory.Snapshot('park.create'),
pghistory.AfterUpdate('park.update'),
pghistory.BeforeDelete('park.delete')
)
class Meta:
# Existing model fields and configuration
```
3. **Migration Generation**
```bash
./manage.py makemigrations --name add_pghistory_tracking
```
### Quality Assurance
1. Verify historical events table creation
2. Test event triggering for CRUD operations
3. Validate context metadata capture