From 144bc96caae888ff77bb240d3de39d900bf4d761 Mon Sep 17 00:00:00 2001 From: Anish Umale Date: Fri, 17 Jan 2025 20:09:10 +0530 Subject: [PATCH] allow disconnecting server via databases.configured.disconnect --- mathesar/rpc/databases/configured.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mathesar/rpc/databases/configured.py b/mathesar/rpc/databases/configured.py index 97ec039375..d70217088a 100644 --- a/mathesar/rpc/databases/configured.py +++ b/mathesar/rpc/databases/configured.py @@ -73,6 +73,7 @@ def disconnect( strict: bool = True, role_name: str = None, password: str = None, + disconnect_db_server: bool = False ) -> None: """ Disconnect a configured database, after removing Mathesar SQL from it. @@ -92,6 +93,11 @@ def disconnect( we fail to remove any objects which we expected to remove. role_name: the username of the role used for upgrading. password: the password of the role used for upgrading. + disconnect_db_server: If True, will delete the stored server + metadata(host, port, role credentials) and also disconnect + all the databases associated with that server from Mathesar. + This is intended for optional use while disconnecting the + last database on the server. """ database = Database.objects.get(id=database_id) database.uninstall_sql( @@ -101,3 +107,5 @@ def disconnect( password=password, ) database.delete() + if disconnect_db_server: + database.server.delete()