old_contents: # Generated by Django 2.2.12 on 2020-05-27 05:13
  from django.db import migrations
  
  from olympia.amo.utils import chunked
  
  
  def add_all_addon_guids_to_addon_guid(apps, schema_editor):
      AddonGUID = apps.get_model('addons', 'AddonGUID')
      Addon = apps.get_model('addons', 'Addon')
  
      batch_size = 1000
      existing_ids = AddonGUID.objects.all().values_list('addon_id', flat=True)
      addon_qs = Addon.unfiltered.exclude(
          guid=None, id__in=existing_ids).values('id', 'guid')
      for addons in chunked(addon_qs, batch_size):
          addonguids = [
              AddonGUID(
                  addon_id=addon['id'], guid=addon['guid']) for addon in addons]
          AddonGUID.objects.bulk_create(addonguids, batch_size)
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('addons', '0004_auto_20191126_1712'),
      ]
  
      operations = [
          migrations.AlterModelTable(
              name='ReusedGUID',
              table='addons_reusedguid',
          ),
          migrations.RenameModel(
              old_name='ReusedGUID',
              new_name='AddonGUID',
          ),
          migrations.AlterModelOptions(
              name='addonguid',
              options={},
          ),
          migrations.RunPython(add_all_addon_guids_to_addon_guid),
      ]
  
new_contents: # Generated by Django 2.2.12 on 2020-05-27 05:13
  from django.db import migrations
  from django.db.models import Q
  
  from olympia.amo.utils import chunked
  
  
  def add_all_addon_guids_to_addon_guid(apps, schema_editor):
      AddonGUID = apps.get_model('addons', 'AddonGUID')
      Addon = apps.get_model('addons', 'Addon')
  
      batch_size = 1000
      existing_ids = AddonGUID.objects.all().values_list('addon_id', flat=True)
      addon_qs = Addon.unfiltered.exclude(
          Q(guid=None) | Q(id__in=existing_ids)).values('id', 'guid')
      for addons in chunked(addon_qs, batch_size):
          addonguids = [
              AddonGUID(
                  addon_id=addon['id'], guid=addon['guid']) for addon in addons]
          AddonGUID.objects.bulk_create(addonguids, batch_size)
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('addons', '0004_auto_20191126_1712'),
      ]
  
      operations = [
          migrations.AlterModelTable(
              name='ReusedGUID',
              table='addons_reusedguid',
          ),
          migrations.RenameModel(
              old_name='ReusedGUID',
              new_name='AddonGUID',
          ),
          migrations.AlterModelOptions(
              name='addonguid',
              options={},
          ),
          migrations.RunPython(add_all_addon_guids_to_addon_guid),
      ]
  
subject: fix migration addons#0005 (#14440)