Skip to content

Commit

Permalink
[MIGRATOR] - ALSO MIGRATE MESSAGES
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanogueira committed Apr 25, 2024
1 parent ff466ec commit 9602e81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion local.yml
Expand Up @@ -102,7 +102,7 @@ services:
command: /start-flower

evolution:
image: davidsongomes/evolution-api
image: atendai/evolution-api
restart: always
ports:
- 8084:8080
Expand Down
Expand Up @@ -2,6 +2,7 @@
from django.core.management.base import BaseCommand
from django_celery_beat.models import PeriodicTask
from instance.models import LiveChatRoom, Connector
from envelope.models import Message

class Command(BaseCommand):
help = "Migrate chats from one connector to the other. This is useful for migrating a number between different connectors."
Expand All @@ -26,6 +27,10 @@ def handle(self, *args, **options):
connector__id=from_connector,
open=True
)
open_messages = Message.objects.filter(
connector__id=from_connector,
open=True
)
if open_chats.count():
from_connector_object = open_chats.first().connector
print("Migrating from connector: ", open_chats.first().connector)
Expand All @@ -42,8 +47,10 @@ def handle(self, *args, **options):
# apply
if options.get("apply"):
print(f"Applying... migrating {open_chats.count()} open chats from {from_connector_object} to {to_connector_object}")
update = open_chats.update(connector_id=to_connector_object.id)
print("RESULT: ", update)
update_rooms = open_chats.update(connector_id=to_connector_object.id)
update_messages = open_messages.update(connector_id=to_connector_object.id)
print("RESULT: ", update_rooms)
print("RESULT: ", update_messages)

else:
print("No chats found on connector with id", from_connector)

0 comments on commit 9602e81

Please sign in to comment.