Skip to content

Commit

Permalink
Fixed historical note backfilling
Browse files Browse the repository at this point in the history
  • Loading branch information
axelstudios committed Mar 13, 2024
1 parent 34a9494 commit 8e9f798
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions seed/migrations/0215_accountability_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ def assign_analyses_to_root_access_level(apps, schema_editor):
analysis.save(update_fields=['access_level_instance'])


@transaction.atomic
def backfill_historical_notes(apps, schema_editor):
Property = apps.get_model('seed', 'Property')
HistoricalNote = apps.get_model('seed', 'HistoricalNote')

properties_ids = Property.objects.filter(historical_note__isnull=True).values_list('id', flat=True)

historical_notes_to_create = [HistoricalNote(property_id=property_id, text='') for property_id in properties_ids]
HistoricalNote.objects.bulk_create(historical_notes_to_create)


class Migration(migrations.Migration):

dependencies = [
Expand Down Expand Up @@ -135,6 +146,9 @@ class Migration(migrations.Migration):
code=assign_analyses_to_root_access_level,
reverse_code=migrations.RunPython.noop,
),
migrations.RunPython(
code=backfill_historical_notes,
),
migrations.AlterField(
model_name='property',
name='access_level_instance',
Expand Down

0 comments on commit 8e9f798

Please sign in to comment.