Files
thrillwiki_django_no_react/memory-bank/workflows/model-migrations.md

1012 B

Model Migration Protocol for History Tracking

Implementation Steps

  1. Base Model Setup

    # 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

    # 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

    ./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