Skip to content

Commit

Permalink
Merge pull request #480 from MTES-MCT/fix-migrations
Browse files Browse the repository at this point in the history
Suppression de migration : erreur de mémoire
  • Loading branch information
alexisig authored Jun 27, 2024
2 parents 4a65a65 + 48339a5 commit ac4a5a1
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions public_data/migrations/0174_auto_20240615_1835.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,12 @@
logger = getLogger(__name__)


def fix_commune_mpoly(apps, schema_editor):
Commune = apps.get_model("public_data", "Commune")
Cerema = apps.get_model("public_data", "Cerema")

to_update = []

communes = Commune.objects.all()
communes.count()

for commune in communes:
cerema = Cerema.objects.get(city_insee=commune.insee)

if commune.mpoly == cerema.mpoly:
# no need to update
break
commune.mpoly = cerema.mpoly
commune.srid_source = cerema.srid_source
to_update.append(commune)

Commune.objects.bulk_update(
to_update,
["mpoly", "srid_source"],
batch_size=1000,
)


class Migration(migrations.Migration):
atomic = False
dependencies = [
("public_data", "0173_alter_zoneartificielle_departement"),
]

operations = [
migrations.RunPython(fix_commune_mpoly),
migrations.RunPython(migrations.RunPython.noop, migrations.RunPython.noop),
]

0 comments on commit ac4a5a1

Please sign in to comment.