Skip to content

Commit

Permalink
temporary workaround for DROP DATABASE issue with currently used DB (#…
Browse files Browse the repository at this point in the history
…582)

* temporary workaround for DROP DATABASE issue with currently used DB
1: do not change the active database when righ-clicking DB tree node
2: run get_tree_info and get_databases against template1 db when
   loadingb DB object tree -> prevents actual DBs from getting "used"

refs: #581

* use template0 in prefer_database
  • Loading branch information
eug3nix authored Jan 22, 2025
1 parent b282c2c commit 4f0cee9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ export default {
label: "Query Database",
icon: "fas cm-all fa-search",
onClick: () => {
let tab_name = `Query: ${tabsStore.selectedPrimaryTab.metaData.selectedDatabase}`
tabsStore.createQueryTab(tab_name)
this.checkCurrentDatabase(this.selectedNode, true, () => {
let tab_name = `Query: ${tabsStore.selectedPrimaryTab.metaData.selectedDatabase}`;
tabsStore.createQueryTab(tab_name);
});
}
},
{
Expand Down Expand Up @@ -2778,15 +2780,13 @@ export default {
this.$refs.tree.select(node.path);
e.preventDefault();
if (!!node.data.contextMenu) {
this.checkCurrentDatabase(node, true, () => {
ContextMenu.showContextMenu({
ContextMenu.showContextMenu({
theme: "pgmanage",
x: e.x,
y: e.y,
zIndex: 1000,
minWidth: 230,
items: this.contextMenu[node.data.contextMenu],
});
});
}
},
Expand Down
10 changes: 8 additions & 2 deletions pgmanage/app/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ def wrap(request, *args, **kwargs):
return wrap


def database_required(check_timeout=True, open_connection=True):
def database_required(check_timeout=True, open_connection=True, prefer_database=None):
def decorator(function):
@session_required
@wraps(function)
def wrap(request, session, *args, **kwargs):
data = request.data
database_name = data.get("database_name")
# FIXME: prefer_database is a temporary workaround to prevent
# issues with DROP DATABASE caused by opening DB backends to
# currently selected database when DB tree is loaded
if prefer_database is not None:
database_name = prefer_database
else:
database_name = data.get("database_name")
database_index = data.get("database_index")
tab_id = data.get("tab_id")
workspace_id=data.get("workspace_id")
Expand Down
4 changes: 2 additions & 2 deletions pgmanage/app/views/tree_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.http import HttpResponse, JsonResponse

@user_authenticated
@database_required(check_timeout=True, open_connection=True)
@database_required(check_timeout=True, open_connection=False, prefer_database='template0')
def get_tree_info(request, database):
try:
data = {
Expand Down Expand Up @@ -808,7 +808,7 @@ def get_schemas(request, database):


@user_authenticated
@database_required(check_timeout=True, open_connection=True)
@database_required(check_timeout=True, open_connection=False, prefer_database='template0')
def get_databases(request, database):
list_databases = []

Expand Down

0 comments on commit 4f0cee9

Please sign in to comment.