From 0a7a28bac0f2dd33ada531150873bfe2b0abb47a Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Fri, 3 May 2019 10:38:10 +0530 Subject: [PATCH] fix: Get data of empty table from pg_stat_all_tables when db-type is postgres --- frappe/config/__init__.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/frappe/config/__init__.py b/frappe/config/__init__.py index 1fe06f9094..b2c1f41d78 100644 --- a/frappe/config/__init__.py +++ b/frappe/config/__init__.py @@ -78,15 +78,22 @@ def get_modules_from_app(app): return active_modules_list def get_all_empty_tables_by_module(): - results = frappe.db.sql(""" - SELECT - name, module - FROM information_schema.tables as i - JOIN tabDocType as d - ON i.table_name = CONCAT('tab', d.name) - WHERE table_rows = 0; - - """) + results = frappe.db.multisql({ + 'mariadb': ''' + SELECT `name`, `module` + FROM information_schema.tables AS i + JOIN `tabDocType` AS d + ON i.table_name = CONCAT('tab', d.name) + WHERE `table_rows` = 0; + ''', + 'postgres': ''' + SELECT "name", "module" + FROM "pg_stat_all_tables" AS i + JOIN "tabDocType" AS d + ON i.relname = CONCAT('tab', d.name) + WHERE n_tup_ins = 0; + ''' + }) empty_tables_by_module = {} @@ -95,7 +102,6 @@ def get_all_empty_tables_by_module(): empty_tables_by_module[module].append(doctype) else: empty_tables_by_module[module] = [doctype] - return empty_tables_by_module def is_domain(module):