Skip to content

Commit 1f83723

Browse files
Merge branch 'master' into jamesdemery/BB2-4250-v3_endpoint_app_specific
2 parents 0b3f054 + 1fcc60e commit 1f83723

File tree

4 files changed

+157
-131
lines changed

4 files changed

+157
-131
lines changed

apps/fhir/bluebutton/management/commands/migrate_fhir_id_to_v2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def migrate_fhir_id_to_v2(apps=None, schema_editor=None) -> None:
1818

1919
apps_mod = apps if apps is not None else global_apps
2020
Crosswalk = apps_mod.get_model('bluebutton', 'Crosswalk')
21-
for crosswalk in Crosswalk.objects.all():
21+
for crosswalk in Crosswalk.objects.iterator(chunk_size=1000):
2222
if getattr(crosswalk, '_fhir_id', None):
2323
crosswalk.fhir_id_v2 = getattr(crosswalk, '_fhir_id') # type: ignore[attr-defined]
2424
crosswalk.save()
2525

2626
ArchivedCrosswalk = apps_mod.get_model('bluebutton', 'ArchivedCrosswalk')
27-
for archived in ArchivedCrosswalk.objects.all():
27+
for archived in ArchivedCrosswalk.objects.iterator(chunk_size=1000):
2828
if getattr(archived, '_fhir_id', None):
2929
archived.fhir_id_v2 = getattr(archived, '_fhir_id') # type: ignore[attr-defined]
3030
archived.save()
@@ -35,13 +35,13 @@ def reverse_migrate_v2_to_fhir_id(apps=None, schema_editor=None) -> None:
3535

3636
apps_mod = apps if apps is not None else global_apps
3737
Crosswalk = apps_mod.get_model('bluebutton', 'Crosswalk')
38-
for crosswalk in Crosswalk.objects.all():
38+
for crosswalk in Crosswalk.objects.iterator(chunk_size=1000):
3939
if getattr(crosswalk, 'fhir_id_v2', None):
4040
crosswalk._fhir_id = getattr(crosswalk, 'fhir_id_v2') # type: ignore[attr-defined]
4141
crosswalk.save()
4242

4343
ArchivedCrosswalk = apps_mod.get_model('bluebutton', 'ArchivedCrosswalk')
44-
for archived in ArchivedCrosswalk.objects.all():
44+
for archived in ArchivedCrosswalk.objects.iterator(chunk_size=1000):
4545
if getattr(archived, 'fhir_id_v2', None):
4646
archived._fhir_id = getattr(archived, 'fhir_id_v2') # type: ignore[attr-defined]
4747
archived.save()

apps/fhir/bluebutton/migrations/0009_migrate_fhir_id_to_v2.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Generated by Django 4.2.24 on 2025-09-23 13:25
22

33
from django.db import migrations, models
4-
from apps.fhir.bluebutton.management.commands.migrate_fhir_id_to_v2 import (
5-
migrate_fhir_id_to_v2,
6-
reverse_migrate_v2_to_fhir_id,
7-
)
84

95
# TODO - Migration is Unapplied
106
# This migration needs to be run after deployment of bluebutton 0008 and when all
@@ -18,8 +14,7 @@ class Migration(migrations.Migration):
1814
]
1915

2016
operations = [
21-
migrations.RunPython(migrate_fhir_id_to_v2, reverse_migrate_v2_to_fhir_id),
22-
migrations.AddConstraint( # After migration happens, add constraint that a fhir_id must be present
17+
migrations.AddConstraint( # After migrate_fhir_id_to_v2 is run, add constraint that a fhir_id_v2 or v3 must be present
2318
model_name='crosswalk',
2419
constraint=models.CheckConstraint(
2520
check=models.Q(fhir_id_v2__isnull=False) | models.Q(fhir_id_v3__isnull=False),

0 commit comments

Comments
 (0)