[patch] Add index on Account and GL Entry table
diff --git a/erpnext/accounts/doctype/account/account.json b/erpnext/accounts/doctype/account/account.json
index fa737a7..8146c63 100644
--- a/erpnext/accounts/doctype/account/account.json
+++ b/erpnext/accounts/doctype/account/account.json
@@ -35,7 +35,7 @@
"permlevel": 0,
"read_only": 1,
"reqd": 1,
- "search_index": 1
+ "search_index": 0
},
{
"default": "0",
@@ -44,7 +44,7 @@
"label": "Is Group",
"permlevel": 0,
"precision": "",
- "search_index": 1
+ "search_index": 0
},
{
"fieldname": "company",
@@ -57,7 +57,7 @@
"permlevel": 0,
"read_only": 1,
"reqd": 1,
- "search_index": 1
+ "search_index": 0
},
{
"fieldname": "root_type",
@@ -147,7 +147,8 @@
"label": "Lft",
"permlevel": 0,
"print_hide": 1,
- "read_only": 1
+ "read_only": 1,
+ "search_index": 1
},
{
"fieldname": "rgt",
@@ -156,7 +157,8 @@
"label": "Rgt",
"permlevel": 0,
"print_hide": 1,
- "read_only": 1
+ "read_only": 1,
+ "search_index": 1
},
{
"fieldname": "old_parent",
@@ -171,7 +173,7 @@
"icon": "icon-money",
"idx": 1,
"in_create": 0,
- "modified": "2015-05-28 14:10:40.606010",
+ "modified": "2015-06-14 20:57:55.471334",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Account",
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json
index 54c7dd6..6d772a6 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.json
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json
@@ -48,7 +48,8 @@
"fieldtype": "Dynamic Link",
"label": "Party",
"options": "party_type",
- "permlevel": 0
+ "permlevel": 0,
+ "search_index": 1
},
{
"fieldname": "cost_center",
@@ -192,7 +193,7 @@
"icon": "icon-list",
"idx": 1,
"in_create": 1,
- "modified": "2015-04-27 20:32:48.246818",
+ "modified": "2015-06-14 20:57:19.800276",
"modified_by": "Administrator",
"module": "Accounts",
"name": "GL Entry",
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 0d1d0de..c647210 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -165,4 +165,5 @@
erpnext.patches.v5_0.portal_fixes
erpnext.patches.v5_0.reset_values_in_tools
execute:frappe.delete_doc("Page", "users")
-erpnext.patches.v5_0.update_material_transferred_for_manufacturing_again
\ No newline at end of file
+erpnext.patches.v5_0.update_material_transferred_for_manufacturing_again
+erpnext.patches.v5_0.index_on_account_and_gl_entry
\ No newline at end of file
diff --git a/erpnext/patches/v5_0/index_on_account_and_gl_entry.py b/erpnext/patches/v5_0/index_on_account_and_gl_entry.py
new file mode 100644
index 0000000..b03b27a
--- /dev/null
+++ b/erpnext/patches/v5_0/index_on_account_and_gl_entry.py
@@ -0,0 +1,22 @@
+from __future__ import unicode_literals
+
+import frappe
+
+def execute():
+ index_map = {
+ "Account": ["parent_account", "lft", "rgt"],
+ "GL Entry": ["posting_date", "account", 'party', "voucher_no"]
+ }
+
+ for dt, indexes in index_map.items():
+ existing_indexes = [d.Key_name for d in frappe.db.sql("""show index from `tab{0}`
+ where Column_name != 'name'""".format(dt), as_dict=1)]
+
+ for old in existing_indexes:
+ if old in ("parent", "group_or_ledger", "is_pl_account", "debit_or_credit", "account_name", "company"):
+ frappe.db.sql("alter table `tab{0}` drop index {1}".format(dt, old))
+ existing_indexes.remove(old)
+
+ for new in indexes:
+ if new not in existing_indexes:
+ frappe.db.sql("alter table `tab{0}` add index ({1})".format(dt, new))
\ No newline at end of file