Skip to content

Commit

Permalink
Merge pull request #2058 from bcgov/gwells-2011-improve-migration
Browse files Browse the repository at this point in the history
[GWELLS-2011] HOTFIX** Reduce time complexity on recent migration
  • Loading branch information
LocalNewsTV authored Nov 20, 2023
2 parents 1c6418c + d7d90b5 commit 13a6799
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/backend/wells/migrations/0143_attach_attachments_to_wells.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from django.db import migrations, models

def populate_wells_with_attachment_table(apps, schema_editor):
A = apps.get_model('wells', 'Well')
B = apps.get_model('wells', 'WellAttachment')
Well = apps.get_model('wells', 'Well')
WellAttachment = apps.get_model('wells', 'WellAttachment')

for a_instance in A.objects.all():
if B.objects.filter(well_tag_number=a_instance):
pass # This entry already has a well attachment associated with it
else:
B.objects.create(well_tag_number=a_instance)
# Get all well tag numbers that don't have an entry in WellAttachment
well_tag_numbers_without_attachment = Well.objects.exclude(wellattachment__isnull=False).values_list('well_tag_number', flat=True)

well_attachments_to_create = [WellAttachment(well_tag_number=tag_number) for tag_number in well_tag_numbers_without_attachment]
WellAttachment.objects.bulk_create(well_attachments_to_create)

class Migration(migrations.Migration):

Expand Down

0 comments on commit 13a6799

Please sign in to comment.