-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New migration to fix old sender & siae encoded fields
- Loading branch information
Showing
1 changed file
with
9 additions
and
29 deletions.
There are no files selected for viewing
38 changes: 9 additions & 29 deletions
38
...e/conversations/migrations/0012_conversation_uuid_sender_conversation_uuid_siae_for_v0.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |