Skip to content

Commit

Permalink
New migration to fix old sender & siae encoded fields
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Sep 18, 2023
1 parent 88496d5 commit 6c8aaf7
Showing 1 changed file with 9 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -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),
]

0 comments on commit 6c8aaf7

Please sign in to comment.