Skip to content

[GWELLS-2011] HOTFIX** Reduce time complexity on recent migration #2058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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