From a148d34cf91a72c0fd327ca6b210cdbda6c98845 Mon Sep 17 00:00:00 2001 From: pacnpal <183241239+pacnpal@users.noreply.github.com> Date: Sat, 8 Feb 2025 21:18:44 -0500 Subject: [PATCH] Implement historical tracking using django-pghistory; add middleware for context capture and update model architecture --- .../decisions/pghistory-integration.md | 45 +++++++++++++++ memory-bank/features/history-visualization.md | 57 +++++++++++++++++++ .../history-tracking/implementation-plan.md | 34 +++++++++++ memory-bank/systemPatterns.md | 18 +++++- memory-bank/workflows/model-migrations.md | 39 +++++++++++++ memory-bank/workflows/moderation.md | 31 ++++++++++ 6 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 memory-bank/decisions/pghistory-integration.md create mode 100644 memory-bank/features/history-visualization.md create mode 100644 memory-bank/projects/history-tracking/implementation-plan.md create mode 100644 memory-bank/workflows/model-migrations.md create mode 100644 memory-bank/workflows/moderation.md diff --git a/memory-bank/decisions/pghistory-integration.md b/memory-bank/decisions/pghistory-integration.md new file mode 100644 index 00000000..5fd76f0a --- /dev/null +++ b/memory-bank/decisions/pghistory-integration.md @@ -0,0 +1,45 @@ +## Decision: Universal Model History via django-pghistory + +### Pattern Implementation +- **Tracking Method**: `pghistory.Snapshot()` applied to all concrete models +- **Inheritance Strategy**: Base model class with history tracking +- **Context Capture**: + ```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) + ``` + +### Integration Scope +1. **Model Layer**: + - All concrete models inherit from `HistoricalModel` + - Automatic event labeling: + ```python + @pghistory.track( + pghistory.Snapshot('model.create'), + pghistory.AfterInsert('model.update'), + pghistory.BeforeDelete('model.delete') + ) + ``` + +2. **Context Middleware**: + ```python + # core/middleware.py + pghistory.context(lambda request: { + 'user': str(request.user) if request.user.is_authenticated else None, + 'ip': request.META.get('REMOTE_ADDR'), + 'user_agent': request.META.get('HTTP_USER_AGENT'), + 'session_key': request.session.session_key + }) + ``` + +3. **Admin Integration**: + - Custom history view for Django Admin + - Version comparison interface \ No newline at end of file diff --git a/memory-bank/features/history-visualization.md b/memory-bank/features/history-visualization.md new file mode 100644 index 00000000..2b2f087a --- /dev/null +++ b/memory-bank/features/history-visualization.md @@ -0,0 +1,57 @@ +## Feature: Unified History Timeline (HTMX Integrated) + +### HTMX Template Pattern +```django +{# history/partials/history_timeline.html #} +