from __future__ import unicode_literals

from django.db import migrations

from credentials.apps.catalog.models import Program
from credentials.apps.records.models import ProgramCertRecord


def seed_program_cert_records(apps, schema_editor):
    for pcr in ProgramCertRecord.objects.all():
        pcr.program = Program.objects.get(uuid=pcr.certificate.program_uuid)
        pcr.save()


class Migration(migrations.Migration):

    dependencies = [
        ('records', '0005_auto_20180717_1953'),
    ]

    operations = [
        migrations.RunPython(seed_program_cert_records),
    ]

from __future__ import unicode_literals

from django.db import migrations

from credentials.apps.catalog.models import Program
from credentials.apps.records.models import ProgramCertRecord


def seed_program_cert_records(apps, schema_editor):
    for pcr in ProgramCertRecord.objects.all():
        program_uuid = pcr.certificate.program_uuid
        site = pcr.certificate.site
        pcr.program = Program.objects.get(site=site, uuid=program_uuid)
        pcr.save()


class Migration(migrations.Migration):

    dependencies = [
        ('records', '0005_auto_20180717_1953'),
    ]

    operations = [
        migrations.RunPython(seed_program_cert_records),
    ]

Add site guarding for ProgramCertRecord data migration
Add site guarding for ProgramCertRecord data migration

  from __future__ import unicode_literals
  
  from django.db import migrations
  
  from credentials.apps.catalog.models import Program
  from credentials.apps.records.models import ProgramCertRecord
  
  
  def seed_program_cert_records(apps, schema_editor):
      for pcr in ProgramCertRecord.objects.all():
+         program_uuid = pcr.certificate.program_uuid
+         site = pcr.certificate.site
-         pcr.program = Program.objects.get(uuid=pcr.certificate.program_uuid)
+         pcr.program = Program.objects.get(site=site, uuid=program_uuid)
          pcr.save()
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('records', '0005_auto_20180717_1953'),
      ]
  
      operations = [
          migrations.RunPython(seed_program_cert_records),
      ]
  
Add site guarding for ProgramCertRecord data migration
## Code Before:
from __future__ import unicode_literals

from django.db import migrations

from credentials.apps.catalog.models import Program
from credentials.apps.records.models import ProgramCertRecord


def seed_program_cert_records(apps, schema_editor):
    for pcr in ProgramCertRecord.objects.all():
        pcr.program = Program.objects.get(uuid=pcr.certificate.program_uuid)
        pcr.save()


class Migration(migrations.Migration):

    dependencies = [
        ('records', '0005_auto_20180717_1953'),
    ]

    operations = [
        migrations.RunPython(seed_program_cert_records),
    ]

## Instruction:
Add site guarding for ProgramCertRecord data migration
## Code After:
from __future__ import unicode_literals

from django.db import migrations

from credentials.apps.catalog.models import Program
from credentials.apps.records.models import ProgramCertRecord


def seed_program_cert_records(apps, schema_editor):
    for pcr in ProgramCertRecord.objects.all():
        program_uuid = pcr.certificate.program_uuid
        site = pcr.certificate.site
        pcr.program = Program.objects.get(site=site, uuid=program_uuid)
        pcr.save()


class Migration(migrations.Migration):

    dependencies = [
        ('records', '0005_auto_20180717_1953'),
    ]

    operations = [
        migrations.RunPython(seed_program_cert_records),
    ]
