Skip to content

Commit

Permalink
squashed migrations; added Bulk update
Browse files Browse the repository at this point in the history
  • Loading branch information
MGS-sails committed Sep 13, 2023
1 parent df9e5c4 commit cd0345f
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Generated by Django 3.2.18 on 2023-09-12 17:40
# Generated by Django 3.2.18 on 2023-09-13 10:24

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('emgapi', '0012_remove_analysisjob_job_operator_2'),
('emgapi', '0010_runextraannotation'),
]

operations = [
migrations.AddField(
model_name='analysisjob',
name='analysis_summary_two',
field=models.JSONField(blank=True, db_column='ANALYSIS_SUMMARY_TWO', null=True),
name='analysis_summary_json',
field=models.JSONField(blank=True, db_column='ANALYSIS_SUMMARY_JSON', null=True),
),
]
18 changes: 0 additions & 18 deletions emgapi/migrations/0011_analysisjob_job_operator_2.py

This file was deleted.

17 changes: 0 additions & 17 deletions emgapi/migrations/0012_remove_analysisjob_job_operator_2.py

This file was deleted.

22 changes: 0 additions & 22 deletions emgapi/migrations/0014_auto_20230912_1741.py

This file was deleted.

22 changes: 0 additions & 22 deletions emgapi/migrations/0015_auto_20230912_1748.py

This file was deleted.

22 changes: 0 additions & 22 deletions emgapi/migrations/0016_auto_20230912_1749.py

This file was deleted.

12 changes: 7 additions & 5 deletions emgapianns/management/commands/import_analysis_summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ def add_arguments(self, parser):

def handle(self, *args, **options):
batch_number = options['batch_number']
batch_size = 10000 # Set your desired batch size here
batch_size = 10000

try:
# Calculate the starting and ending index for the batch
start_index = (batch_number - 1) * batch_size
end_index = batch_number * batch_size

# Get AnalysisJob records for the specified batch
analysis_jobs = AnalysisJob.objects.all()[start_index:end_index]

# Print the number of records in the batch
self.stdout.write(self.style.SUCCESS(f'Processing batch {batch_number} of {len(analysis_jobs)} records.'))

updated_records = []

for analysis_job in analysis_jobs:
analysis_summary = analysis_job.analysis_summary
if analysis_summary:
analysis_job.analysis_summary_json = analysis_summary
analysis_job.save()
updated_records.append(analysis_job)

if updated_records:
AnalysisJob.objects.bulk_update(updated_records, ['analysis_summary_json'])

self.stdout.write(self.style.SUCCESS(f'Values copied successfully for batch {batch_number}.'))
except AnalysisJob.DoesNotExist:
Expand Down

0 comments on commit cd0345f

Please sign in to comment.