Skip to content

Commit

Permalink
Use raw SQL migration to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Aug 1, 2023
1 parent e325e32 commit eec2c53
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions isic/ingest/migrations/0038_migrate_copyright_license.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# Generated by Django 4.1.10 on 2023-07-31 22:25

from django.db import migrations
from django.db import connection, migrations


def migrate_default_copyright_license(apps, schema_editor):
Accession = apps.get_model("ingest", "Accession")

objs = []
for accession in (
Accession.objects.select_related("cohort").filter(copyright_license=None).iterator()
):
accession.copyright_license = accession.cohort.default_copyright_license
objs.append(accession)
Accession.objects.bulk_update(objs, ["copyright_license"], batch_size=1_000)
with connection.cursor() as cursor:
cursor.execute(
"update ingest_accession set copyright_license = ingest_cohort.default_copyright_license from ingest_cohort where ingest_accession.cohort_id = ingest_cohort.id" # noqa: E501
)


class Migration(migrations.Migration):
Expand Down

0 comments on commit eec2c53

Please sign in to comment.