From 68196bc96609d2ddbb474f1cd5cca4204ae38a8e Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 26 Jun 2012 12:15:15 +0530 Subject: [PATCH] delete records in child table where parent is missing or parent is like old_par% --- .../june_2012/delete_old_parent_entries.py | 17 +++++++++++++++++ erpnext/patches/patch_list.py | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 erpnext/patches/june_2012/delete_old_parent_entries.py diff --git a/erpnext/patches/june_2012/delete_old_parent_entries.py b/erpnext/patches/june_2012/delete_old_parent_entries.py new file mode 100644 index 0000000000..c74f609e0b --- /dev/null +++ b/erpnext/patches/june_2012/delete_old_parent_entries.py @@ -0,0 +1,17 @@ +def execute(): + """delete entries of child table having parent like old_par%% or ''""" + import webnotes + res = webnotes.conn.sql("""\ + select dt.name from `tabDocType` dt + where ifnull(dt.istable, 0)=1 and + exists ( + select * from `tabDocField` df + where df.fieldtype='Table' and + df.options=dt.name + )""") + for r in res: + if r[0]: + webnotes.conn.sql("""\ + delete from `tab%s` + where (ifnull(parent, '')='' or parent like "old_par%%") and + ifnull(parenttype, '')!=''""" % r[0]) \ No newline at end of file diff --git a/erpnext/patches/patch_list.py b/erpnext/patches/patch_list.py index 03c0f27dd6..5e5f4c9800 100644 --- a/erpnext/patches/patch_list.py +++ b/erpnext/patches/patch_list.py @@ -452,4 +452,9 @@ patch_list = [ 'patch_file': 'alter_tabsessions', 'description': "alter tabsessions to change user column definition" }, + { + 'patch_module': 'patches.june_2012', + 'patch_file': 'delete_old_parent_entries', + 'description': "delete entries of child table having parent like old_par%% or ''" + }, ] \ No newline at end of file