Allow migrating away from mongo (#3253)

* Restore mongo driver

* make it possible to convert

* style

* add in known issues with other backends while at it
This commit is contained in:
Michael H
2020-01-08 13:41:35 -05:00
committed by GitHub
parent 35c27c5741
commit 1c75c47a9c
4 changed files with 473 additions and 4 deletions

View File

@@ -110,7 +110,10 @@ def get_storage_type():
print()
print("Please choose your storage backend (if you're unsure, choose 1).")
print("1. JSON (file storage, requires no database).")
print("2. PostgreSQL")
print(
"2. PostgreSQL (Requires a database server)"
"\n(Warning: You cannot convert postgres instances to other backends yet)"
)
storage = input("> ")
try:
storage = int(storage)
@@ -196,7 +199,7 @@ def get_target_backend(backend) -> BackendType:
async def do_migration(
current_backend: BackendType, target_backend: BackendType
) -> Dict[str, Any]:
cur_driver_cls = drivers.get_driver_class(current_backend)
cur_driver_cls = drivers._get_driver_class_include_old(current_backend)
new_driver_cls = drivers.get_driver_class(target_backend)
cur_storage_details = data_manager.storage_details()
new_storage_details = new_driver_cls.get_config_details()
@@ -375,7 +378,7 @@ def delete(
@cli.command()
@click.argument("instance", type=click.Choice(instance_list))
@click.argument("backend", type=click.Choice(["json", "postgres"]))
@click.argument("backend", type=click.Choice(["json"])) # TODO: GH-3115
def convert(instance, backend):
"""Convert data backend of an instance."""
current_backend = get_current_backend(instance)
@@ -387,8 +390,10 @@ def convert(instance, backend):
loop = asyncio.get_event_loop()
if current_backend in (BackendType.MONGOV1, BackendType.MONGO):
if current_backend == BackendType.MONGOV1:
raise RuntimeError("Please see the 3.2 release notes for upgrading a bot using mongo.")
elif current_backend == BackendType.POSTGRES: # TODO: GH-3115
raise RuntimeError("Converting away from postgres isn't currently supported")
else:
new_storage_details = loop.run_until_complete(do_migration(current_backend, target))