delete records in child table where parent is missing or parent is like
old_par%
This commit is contained in:
parent
81fa802e09
commit
68196bc966
17
erpnext/patches/june_2012/delete_old_parent_entries.py
Normal file
17
erpnext/patches/june_2012/delete_old_parent_entries.py
Normal file
@ -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])
|
@ -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 ''"
|
||||
},
|
||||
]
|
Loading…
Reference in New Issue
Block a user