Skip to content

Commit

Permalink
Merge pull request #4136 from mathesar-foundation/disconnect_server
Browse files Browse the repository at this point in the history
Allow disconnecting server via `databases.configured.disconnect`
  • Loading branch information
seancolsen authored Jan 17, 2025
2 parents 5dbf8be + a068fc6 commit 6ea630d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mathesar/rpc/databases/configured.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -92,6 +93,10 @@ 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) 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(
Expand All @@ -101,3 +106,6 @@ def disconnect(
password=password,
)
database.delete()
server_db_count = len(Database.objects.filter(server=database.server))
if disconnect_db_server and server_db_count == 0:
database.server.delete()

0 comments on commit 6ea630d

Please sign in to comment.