Skip to content

Commit

Permalink
Merge pull request #4451 from betagouv/raphodn/backend-waste-action-s…
Browse files Browse the repository at this point in the history
…kip-data-migration

CMS : ignorer la migration des données WasteAction si il y a une erreur
  • Loading branch information
raphodn authored Sep 16, 2024
2 parents 8f263bd + a663f87 commit f0ad49c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 7 additions & 4 deletions cms/migrations/0005_delete_wasteaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@


def backup_waste_action_data(apps, schema_editor):
WasteAction = apps.get_model("cms", "WasteAction")
data = serialize("json", WasteAction.objects.all())
with open("waste_action_backup.json", "w") as f:
f.write(data)
try:
WasteAction = apps.get_model("cms", "WasteAction")
data = serialize("json", WasteAction.objects.all())
with open("waste_action_backup.json", "w") as f:
f.write(data)
except:
pass


class Migration(migrations.Migration):
Expand Down
15 changes: 9 additions & 6 deletions data/migrations/0152_wasteaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@


def restore_waste_action_data(apps, schema_editor):
with open("waste_action_backup.json", "r") as f:
data = f.read()
data = data.replace("cms.wasteaction", "data.wasteaction")
for obj in deserialize("json", data):
obj.save()
os.remove("waste_action_backup.json")
try:
with open("waste_action_backup.json", "r") as f:
data = f.read()
data = data.replace("cms.wasteaction", "data.wasteaction")
for obj in deserialize("json", data):
obj.save()
os.remove("waste_action_backup.json")
except: # noqa
pass


class Migration(migrations.Migration):
Expand Down

0 comments on commit f0ad49c

Please sign in to comment.