33 lines
791 B
Python
33 lines
791 B
Python
|
# Generated by Django 3.2.18 on 2024-08-22 03:12
|
||
|
|
||
|
from django.db import migrations, models
|
||
|
|
||
|
|
||
|
def remove_duplicates(apps, schema_editor):
|
||
|
Room = apps.get_model("chat_box", "Room")
|
||
|
seen = set()
|
||
|
|
||
|
for room in Room.objects.all():
|
||
|
pair = (room.user_one_id, room.user_two_id)
|
||
|
reverse_pair = (room.user_two_id, room.user_one_id)
|
||
|
|
||
|
if pair in seen or reverse_pair in seen:
|
||
|
room.delete()
|
||
|
else:
|
||
|
seen.add(pair)
|
||
|
|
||
|
|
||
|
class Migration(migrations.Migration):
|
||
|
|
||
|
dependencies = [
|
||
|
("chat_box", "0015_room_last_msg_time"),
|
||
|
]
|
||
|
|
||
|
operations = [
|
||
|
migrations.RunPython(remove_duplicates),
|
||
|
migrations.AlterUniqueTogether(
|
||
|
name="room",
|
||
|
unique_together={("user_one", "user_two")},
|
||
|
),
|
||
|
]
|