Back to all reviewers

Ensure migration compatibility

prowler-cloud/prowler
Based on 4 comments
Python

When modifying database schemas through migrations, ensure compatibility with existing data. For new required fields, use `null=True` or provide appropriate default values to prevent failures on existing records. Always keep migration files synchronized with model changes, and test migrations against a representative dataset before deploying to production.

Migrations Python

Reviewer Prompt

When modifying database schemas through migrations, ensure compatibility with existing data. For new required fields, use null=True or provide appropriate default values to prevent failures on existing records. Always keep migration files synchronized with model changes, and test migrations against a representative dataset before deploying to production.

For fields added to models that may already have data:

# Good practice:
first_seen_at = models.DateTimeField(null=True, editable=False)
# Or with a default value:
first_seen_at = models.DateTimeField(default=timezone.now, editable=False)

# Problematic - will fail on existing data:
first_seen_at = models.DateTimeField(editable=False)  # No null or default

For complex migrations involving raw SQL or custom Python functions, define and test reverse operations (RunSQL or RunPython). When true reversal is not possible (like adding enum values), use migrations.RunSQL.noop to explicitly indicate this limitation. Consider performance impacts when migrations affect large datasets, as this may block application startup.

4
Comments Analyzed
Python
Primary Language
Migrations
Category

Source Discussions