-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BASE] added open chat connector migration command
- Loading branch information
1 parent
8632e66
commit c9db9de
Showing
2 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
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,7 +1,20 @@ | ||
DEPLOY | ||
DEPLOY / MIGRATION | ||
====================================================================== | ||
|
||
COOKIE CUTTER | ||
---------------------------------------------------------------------- | ||
|
||
Check this out: https://github.com/dudanogueira/rocketconnect_cookiecutter | ||
Check this out: https://github.com/dudanogueira/rocketconnect_cookiecutter | ||
|
||
|
||
Open Chat Connector Migration Command | ||
---------------------------------------------------------------------- | ||
|
||
There is a new migration command that will help you migrating all open chats from connector X to connector Y | ||
|
||
this is helpful if you want to change connectors. This will basically change in bulk the connector from the open chats of a given connector. | ||
|
||
|
||
❯ docker compose -f local.yml run --rm django python manage.py migrate_connector_chat 6 2 --apply | ||
|
||
this will apply the migration from open chats at connector id 6 to connector id 2 |
49 changes: 49 additions & 0 deletions
49
rocket_connect/instance/management/commands/migrate_connector_chat.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.core.management.base import BaseCommand | ||
from django_celery_beat.models import PeriodicTask | ||
from instance.models import LiveChatRoom, Connector | ||
|
||
class Command(BaseCommand): | ||
help = "Migrate chats from one connector to the other. This is useful for migrating a number between different connectors." | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("from", nargs=1, type=int) | ||
parser.add_argument("to", nargs=1, type=int) | ||
|
||
# Named (optional) arguments | ||
parser.add_argument( | ||
"--apply", | ||
action="store_true", | ||
help="Apply the migration", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
print(options) | ||
# get from | ||
from_connector = int(options.get("from")[0]) | ||
to_connector = int(options.get("to")[0]) | ||
open_chats = LiveChatRoom.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) | ||
print(open_chats) | ||
print(open_chats.count(), "Chats found.") | ||
# get the to connector | ||
try: | ||
to_connector_object = Connector.objects.get(id=to_connector) | ||
print("Migrating to this connector: ", to_connector_object) | ||
except Connector.DoesNotExist: | ||
print("Error! Connector to migrate not found") | ||
to_connector_object = None | ||
# select and print all the findings | ||
# 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) | ||
|
||
else: | ||
print("No chats found on connector with id", from_connector) |