mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-07-07 04:53:25 -05:00
Fix an issue where the default server-group is being deleted if the load-server json file contains no servers. #6602
This commit is contained in:
parent
fe753bd272
commit
e587ef404c
|
@ -182,6 +182,10 @@ class ServerGroupView(NodeView):
|
|||
).order_by("id")
|
||||
|
||||
# if server group id is 1 we won't delete it.
|
||||
# This matches the behavior of
|
||||
# web/pgadmin/utils/__init.py__#clear_database_servers
|
||||
# called by the setup script when importing and replacing servers:
|
||||
# `python setup.py --load-servers input_file.json --replace`
|
||||
sg = groups.first()
|
||||
|
||||
shared_servers = Server.query.filter_by(servergroup_id=gid,
|
||||
|
|
|
@ -781,14 +781,15 @@ def clear_database_servers(load_user=current_user, from_setup=False):
|
|||
for server in servers:
|
||||
db.session.delete(server)
|
||||
|
||||
# Remove all groups
|
||||
groups = ServerGroup.query.filter_by(user_id=user_id)
|
||||
# Remove all servergroups except for the first
|
||||
# This matches the UI behavior in
|
||||
# web/pgadmin/browser/server_groups/__init__.py#delete
|
||||
# TODO: Investigate if we can skip the first with an `offset(1)`
|
||||
groups = ServerGroup.query.filter_by(user_id=user_id).order_by("id")
|
||||
default_sg = groups.first()
|
||||
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)
|
||||
if group.id != default_sg.id:
|
||||
db.session.delete(group)
|
||||
|
||||
try:
|
||||
db.session.commit()
|
||||
|
|
Loading…
Reference in New Issue
Block a user