From afdb455b5a73e6c6c9791ea175943e862480d9c1 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 14 Mar 2024 10:56:17 +0530 Subject: [PATCH 1/2] fix: log psql console usage as well Signed-off-by: Akhil Narang --- frappe/commands/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 115249f4a9..d3dacbe29b 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -513,9 +513,12 @@ def postgres(context, extra_args): """ Enter into postgres console for a given site. """ + from frappe.utils import get_site_path + site = get_site(context) frappe.init(site=site) frappe.conf.db_type = "postgres" + os.environ["PSQL_HISTORY"] = os.path.abspath(get_site_path("logs", "postgresql_console.log")) _enter_console(extra_args=extra_args) From d0923b0cd9905a29257e90ca340dae46f6e33bf4 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 14 Mar 2024 11:09:50 +0530 Subject: [PATCH 2/2] refactor: move histfile setting into helper function This will ensure even users of `bench db-console` can use it Signed-off-by: Akhil Narang --- frappe/commands/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index d3dacbe29b..a556bac36d 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -497,12 +497,9 @@ def mariadb(context, extra_args): """ Enter into mariadb console for a given site. """ - from frappe.utils import get_site_path - site = get_site(context) frappe.init(site=site) frappe.conf.db_type = "mariadb" - os.environ["MYSQL_HISTFILE"] = os.path.abspath(get_site_path("logs", "mariadb_console.log")) _enter_console(extra_args=extra_args) @@ -513,17 +510,20 @@ def postgres(context, extra_args): """ Enter into postgres console for a given site. """ - from frappe.utils import get_site_path - site = get_site(context) frappe.init(site=site) frappe.conf.db_type = "postgres" - os.environ["PSQL_HISTORY"] = os.path.abspath(get_site_path("logs", "postgresql_console.log")) _enter_console(extra_args=extra_args) def _enter_console(extra_args=None): from frappe.database import get_command + from frappe.utils import get_site_path + + if frappe.conf.db_type == "mariadb": + os.environ["MYSQL_HISTFILE"] = os.path.abspath(get_site_path("logs", "mariadb_console.log")) + else: + os.environ["PSQL_HISTORY"] = os.path.abspath(get_site_path("logs", "postgresql_console.log")) bin, args, bin_name = get_command( host=frappe.conf.db_host,