Skip to content

Commit

Permalink
Merge pull request #10911 from Ostap-Zherebetskyi/fix/preprint_manage…
Browse files Browse the repository at this point in the history
…ment_command

[ENG-6856] Fix migration command to include last preprint
  • Loading branch information
cslzchen authored Jan 14, 2025
2 parents 87b3059 + e860b30 commit 8f71b73
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions osf/management/commands/migrate_non_versioned_preprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ def handle(self, *args, **options):
Preprint = apps.get_model('osf', 'Preprint')

content_type_id = ContentType.objects.get_for_model(Preprint).id
first_id = Preprint.objects.filter(versioned_guids__isnull=True).order_by('id').first().id
last_id = Preprint.objects.filter(versioned_guids__isnull=True).order_by('id').last().id
qs = Preprint.objects.filter(versioned_guids__isnull=True).order_by('id')
if not qs.exists():
self.stdout.write(self.style.WARNING('No preprints to migrate!'))
return
first_id = qs.first().id
last_id = qs.last().id

vq_list = []
p_batch_ids = [[x, x + batch_size - 1] for x in range(first_id, last_id, batch_size)]
total_migrated = 0
p_batch_ids = [[x, x + batch_size - 1] for x in range(first_id, last_id + 1, batch_size)]

for ids in tqdm(p_batch_ids, desc='Processing', unit='batch'):
preprints_list = Preprint.objects.filter(id__range=ids)
Expand All @@ -68,8 +73,10 @@ def handle(self, *args, **options):
if vq_list:
if not dry_run:
GuidVersionsThrough.objects.bulk_create(vq_list, batch_size=len(vq_list))
total_migrated += len(vq_list)
vq_list = []
success_message = f'Migration completed successfully! [{total_migrated}] preprints have been migrated.'
if dry_run:
self.stdout.write(self.style.WARNING('DRY_RUN: Migration has completed successfully!'))
self.stdout.write(self.style.WARNING(f'DRY_RUN: {success_message}'))
else:
self.stdout.write(self.style.SUCCESS('Migration completed successfully!'))
self.stdout.write(self.style.SUCCESS(success_message))

0 comments on commit 8f71b73

Please sign in to comment.