Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default ServerGroup to user loading 0 Servers #6855

Merged
14 changes: 10 additions & 4 deletions web/pgadmin/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,16 @@ def load_database_servers(input_file, selected_servers,

servers_added = servers_added + 1

# If `clear_database_servers` has dropped Servers and ServerGroups
# and if the file has an empty array for "Servers",
# recreate the default ServerGroup for this user just as if they were a new user.
# This prevents an issue where a user with 0 ServerGroups could not manually
# create new Servers and ServerGroups.
if len(groups) == 0 and len(data["Servers"]) == 0:
benjaminjb marked this conversation as resolved.
Show resolved Hide resolved
server_group = ServerGroup(user_id=user_id, name="Servers")
db.session.add(server_group)
db.session.commit()

msg = ADD_SERVERS_MSG % (groups_added, servers_added)
print(msg)

Expand All @@ -782,10 +792,6 @@ def clear_database_servers(load_user=current_user, from_setup=False):
groups = ServerGroup.query.filter_by(user_id=user_id)
for group in groups:
db.session.delete(group)
servers = Server.query.filter_by(user_id=user_id)

for server in servers:
db.session.delete(server)

try:
db.session.commit()
Expand Down