From 6c8aaf79e6154db0454b9f665602ff50a86db1f6 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 18 Sep 2023 11:07:45 +0200 Subject: [PATCH] New migration to fix old sender & siae encoded fields --- ...id_sender_conversation_uuid_siae_for_v0.py | 38 +++++-------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/lemarche/conversations/migrations/0012_conversation_uuid_sender_conversation_uuid_siae_for_v0.py b/lemarche/conversations/migrations/0012_conversation_uuid_sender_conversation_uuid_siae_for_v0.py index 1e662cb52..e5ec5d8e4 100644 --- a/lemarche/conversations/migrations/0012_conversation_uuid_sender_conversation_uuid_siae_for_v0.py +++ b/lemarche/conversations/migrations/0012_conversation_uuid_sender_conversation_uuid_siae_for_v0.py @@ -1,42 +1,22 @@ # Generated by Django 4.2.2 on 2023-09-05 18:03 -import uuid +from django.db import migrations -from django.db import migrations, models - -def set_uuids(apps, schema_editor): +def set_uuids_again(apps, schema_editor): Conversation = apps.get_model("conversations", "Conversation") - for conversation in Conversation.objects.all(): - siae = conversation.siae - conversation.sender_encoded = ( - f"{conversation.sender_first_name}_{conversation.sender_last_name}_{str(uuid.uuid4())[:4]}" - ) - conversation.siae_encoded = f"{siae.contact_first_name}_{siae.contact_last_name}_{str(uuid.uuid4())[:4]}" + for conversation in Conversation.objects.filter(version=0): + conversation.sender_encoded = "" + conversation.set_sender_encoded() + conversation.siae_encoded = "" + conversation.set_siae_encoded() conversation.save() class Migration(migrations.Migration): dependencies = [ - ("conversations", "0009_conversation_validated_at"), + ("conversations", "0011_conversation_sender_siae_encoded_unique"), ] operations = [ - migrations.AddField( - model_name="conversation", - name="sender_encoded", - field=models.CharField(db_index=True, default="", max_length=255, verbose_name="Identifiant initiateur"), - preserve_default=False, - ), - migrations.AddField( - model_name="conversation", - name="siae_encoded", - field=models.CharField(db_index=True, default="", max_length=255, verbose_name="Identifiant structure"), - preserve_default=False, - ), - migrations.AlterField( - model_name="conversation", - name="version", - field=models.PositiveIntegerField(default=1, verbose_name="Version"), - ), - migrations.RunPython(set_uuids, migrations.RunPython.noop), + migrations.RunPython(set_uuids_again, migrations.RunPython.noop), ]