Skip to content

Commit eae052e

Browse files
eug3nixplucik
authored andcommitted
temporary workaround for DROP DATABASE issue with currently used DB (#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
1 parent 7262e27 commit eae052e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

pgmanage/app/static/pgmanage_frontend/src/components/TreePostgresql.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ export default {
112112
label: "Query Database",
113113
icon: "fas cm-all fa-search",
114114
onClick: () => {
115-
let tab_name = `Query: ${tabsStore.selectedPrimaryTab.metaData.selectedDatabase}`
116-
tabsStore.createQueryTab(tab_name)
115+
this.checkCurrentDatabase(this.selectedNode, true, () => {
116+
let tab_name = `Query: ${tabsStore.selectedPrimaryTab.metaData.selectedDatabase}`;
117+
tabsStore.createQueryTab(tab_name);
118+
});
117119
}
118120
},
119121
{
@@ -2778,15 +2780,13 @@ export default {
27782780
this.$refs.tree.select(node.path);
27792781
e.preventDefault();
27802782
if (!!node.data.contextMenu) {
2781-
this.checkCurrentDatabase(node, true, () => {
2782-
ContextMenu.showContextMenu({
2783+
ContextMenu.showContextMenu({
27832784
theme: "pgmanage",
27842785
x: e.x,
27852786
y: e.y,
27862787
zIndex: 1000,
27872788
minWidth: 230,
27882789
items: this.contextMenu[node.data.contextMenu],
2789-
});
27902790
});
27912791
}
27922792
},

pgmanage/app/utils/decorators.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ def wrap(request, *args, **kwargs):
1717
return wrap
1818

1919

20-
def database_required(check_timeout=True, open_connection=True):
20+
def database_required(check_timeout=True, open_connection=True, prefer_database=None):
2121
def decorator(function):
2222
@session_required
2323
@wraps(function)
2424
def wrap(request, session, *args, **kwargs):
2525
data = request.data
26-
database_name = data.get("database_name")
26+
# FIXME: prefer_database is a temporary workaround to prevent
27+
# issues with DROP DATABASE caused by opening DB backends to
28+
# currently selected database when DB tree is loaded
29+
if prefer_database is not None:
30+
database_name = prefer_database
31+
else:
32+
database_name = data.get("database_name")
2733
database_index = data.get("database_index")
2834
tab_id = data.get("tab_id")
2935
workspace_id=data.get("workspace_id")

pgmanage/app/views/tree_postgresql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.http import HttpResponse, JsonResponse
66

77
@user_authenticated
8-
@database_required(check_timeout=True, open_connection=True)
8+
@database_required(check_timeout=True, open_connection=False, prefer_database='template0')
99
def get_tree_info(request, database):
1010
try:
1111
data = {
@@ -810,7 +810,7 @@ def get_schemas(request, database):
810810

811811

812812
@user_authenticated
813-
@database_required(check_timeout=True, open_connection=True)
813+
@database_required(check_timeout=True, open_connection=False, prefer_database='template0')
814814
def get_databases(request, database):
815815
list_databases = []
816816

0 commit comments

Comments
 (0)