MCPcopy Index your code
hub / github.com/pgadmin-org/pgadmin4 / clear_database_servers

Function clear_database_servers

web/pgadmin/utils/__init__.py:826–861  ·  view source on GitHub ↗

Clear groups and servers configurations.

(load_user=current_user, from_setup=False,
                           auth_source=INTERNAL)

Source from the content-addressed store, hash-verified

824
825
826def clear_database_servers(load_user=current_user, from_setup=False,
827 auth_source=INTERNAL):
828 """Clear groups and servers configurations.
829 """
830 user = _does_user_exist(load_user, from_setup, auth_source)
831 if user is None:
832 return False
833
834 user_id = user.id
835
836 # Remove all servers
837 servers = Server.query.filter_by(user_id=user_id)
838 for server in servers:
839 db.session.delete(server)
840
841 # Remove all servergroups except for the first
842 # This matches the UI behavior in
843 # web/pgadmin/browser/server_groups/__init__.py#delete
844 # TODO: Investigate if we can skip the first with an `offset(1)`
845 groups = ServerGroup.query.filter_by(user_id=user_id).order_by("id")
846 default_sg = groups.first()
847 for group in groups:
848 if group.id != default_sg.id:
849 db.session.delete(group)
850
851 try:
852 db.session.commit()
853 except Exception as e:
854 error_msg = \
855 gettext("Error clearing server configuration with error (%s)" %
856 str(e))
857 if from_setup:
858 print(error_msg)
859 sys.exit(1)
860
861 return False, error_msg
862
863
864def _does_user_exist(user, from_setup, auth_source=INTERNAL):

Callers 2

load_serversMethod · 0.90
saveFunction · 0.90

Calls 4

_does_user_existFunction · 0.85
gettextFunction · 0.85
firstMethod · 0.65
deleteMethod · 0.45

Tested by

no test coverage detected